Regex lookbehind and lookahead at same time

Hi ,
Can we use lookahead and lookbehind at same time in regex.
“My Performance appraisal cycle goal”
I need find 1 word present “appraisal” and 1 word after “appraisal”.

Regards,
Sushant

1 Like

@sshitol

Try below regular expression:

                               (?>\w+){1}(?>\sappraisal)(?>\s\w+){1}

image

1 Like

HI @sshitol

(?=Performance).*?(?=go)

You can try this expression
Thanks
Ashwin S

2 Likes

Hi @lakshman,
It works for me thanks.
Can you pls let me know if i want to convert output of regex(“ienumerable”) into string then what is the way to do that.
Because i need to check specific word present in regex output or not using if condition

Regards,
Susahnt

3 Likes

@sshitol

Use this:

System.Text.RegularExpression.Regex.Matches(“your input string”,(?>\w+){1}(?>\sappraisal)(?>\s\w+){1})(0).Tostring

2 Likes

Hi @lakshman,
what is the use of this

Regards,
Susahnt

1 Like

@sshitol

Here, I used Matches Method. It will find all matched values in the given string and will give output as collection of match values.

matchValue(0).Tostring - will give First match

matchValue(1).Tostring - will give Second match

Etc…

1 Like

@sshitol

Try below one in IF condition.

matchValue(0).Tostring.Contains(“Required word”)
Then “word found”
Else “word not found”

2 Likes

Hi @lakshman,
It works.
One last help, how to check if the given regex output ienumerable contains any number or not ?
“hello 1234 s1s sushant” this is the output of regex.
so I need to check whether this output contains any number in between chararcters or words.
How to check that
Regards,
Sushant

3 Likes

@sshitol

Again use regular expression to check whether String contains any number of not.

System.Text.RegularExpression.Regex.IsMatche(inputString, [0-9])

It will give Boolean value as output. If it is true then input String contains numbers else not.

5 Likes

Hi @lakshman
I am facing issue in regex.

If yoy see the last line in Test string it is also having “By” word but its not highlighting word which are present before and after that.
Can you help me. I guess because of . its creating problem
I need such regex which can accept anyvalue (number,word,special character) after and before “by”

image

1 Like

Hi @lakshman,
Could you pls help me out on above issue

1 Like

@sshitol

First replace dot . with nothing and then apply regular expression to fetch required data.

yourString = yourString.Replace(".","")

1 Like

Hi @lakshman,
Actually i need to use this regex on pdf which containing price. In this case if i replace . by “” then price of actual product will get change.
Is it possible to do something in regex which u shared earlier.
Because this issue was happening for all special character not only for .

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.