Sunil
asked on
regex pattern to match substring without teminating character
I need help to build regular expression pattern in c using regex.h. I have a string having pipe separated fields.
foo|this is first field.|this is second field.|this is third filed.
I have to create pattern at run time to match complete field by sub string of it. for example "second" will match "this is second field." and "first" will match "this is first field." but "third" should match "this is third filed" without including terminating . character.
If there are more then one . at the end then it should match them except last . character for example if third filed is "|this is third field..." then it should match "this is third field.."
can some one please help to create this pattern.
foo|this is first field.|this is second field.|this is third filed.
I have to create pattern at run time to match complete field by sub string of it. for example "second" will match "this is second field." and "first" will match "this is first field." but "third" should match "this is third filed" without including terminating . character.
If there are more then one . at the end then it should match them except last . character for example if third filed is "|this is third field..." then it should match "this is third field.."
can some one please help to create this pattern.
ASKER
[^|]*first[^|]*(?<!.$) is not working
also if a field appears more than once then it should match . at the end ,except terminating . character.
if string is
|first field.|first field.
then pattern should match "first field." and "first field"
also if a field appears more than once then it should match . at the end ,except terminating . character.
if string is
|first field.|first field.
then pattern should match "first field." and "first field"
then try
[^|]*first[^|]*(?<!\.$)
works here see link
https://regex101.com/r/lGVvm9/1/
https://regex101.com/r/lGVvm9/1/
ASKER
yes this is working correct here but I am using regex.h in c language, there it is not working and I need help if it is possible using regex.h.
this is the pattern I am using in c
([^\\|]*first[^\\|]*(?<!\\ .$))
but it is crashing
Program received signal SIGSEGV, Segmentation fault.
0x0000003ca80c948f in regexec@@GLIBC_2.3.4 () from /lib64/libc.so.6
this is the pattern I am using in c
([^\\|]*first[^\\|]*(?<!\\
but it is crashing
Program received signal SIGSEGV, Segmentation fault.
0x0000003ca80c948f in regexec@@GLIBC_2.3.4 () from /lib64/libc.so.6
Sorry Can't help further
ASKER
Thank everyone for the help I was able to solve my problem using ([^|]*first[^|]*)(([|.])|$ ).
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
pls try
Open in new window
REgards