1

I have been stuck with this regex issue for a long time now. I have the following string.

[{"op": "replace", "path": "/endDate", "value": "#{$PurchaseOrderExtensions.findOne(_extid).getEndDate().toString()}"}] 

I am totally confused how to extract the word _extid which is within the round brackets. The confusing part is that there are many round brackets. I need to extract only the one after the occurrence of findOne.

I tried the following regular expressions but none of them even matched the string to extract the one after findOne.

/\{(\(\w+\))\}/? /\\((\\w+)\\)/? and many more... 

What mistake am I doing here?

4
  • 2
    Input looks like a JSON, why not use a JSON parser? Commented Apr 13, 2016 at 16:10
  • 2
    "What mistake am I doing here?" you're not using a JSON parser is one thing. The fact you have code inside of your string is another bad thing; likely to be evald later or some kind of dynamic execution. Commented Apr 13, 2016 at 16:25
  • are you saying the extid is the data, which may change? you want to get to findOne(whaterver is here) ? Commented Apr 13, 2016 at 16:44
  • 1
    @ash I know how to use JSON parsing. But I am using Xtend, which does not support any JSON parsing like we use in basic Java. In fact, it does not allow to add any extra java jars. And I do not think "not using JSON parser" is a mistake. It is a choice. Plus I have put in this code in this string with some purpose. Commented Apr 13, 2016 at 21:15

4 Answers 4

1

You may just find for findOne in your regex:

findOne\((\w+)\) 

Then you can get your string from the inner capture group.

Sign up to request clarification or add additional context in comments.

Comments

1
'(?<=findOne)\(.*?\)' 

Example

grep -Po '(?<=findOne)\(.*?\)' file 

or

grep -Po 'findOne\K\(.*?\)' file 

Comments

0

Why won't you just include findOne into your expression?

Like:

/\.findOne\((.*?)\)/

depending on the language and use, you may need to double the backslashes, or as mentioned - just use JSON parser

Comments

0

Could you use something like this that captures what is inside round brackets:

\([a-z1-9_]*\) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.