2

There is a function script, var f = new Process("name01", "code01", "version01"); I want to use a regular expression to filter to get the name01 property. But this filter: "([^"]+)" works for the all properties.

"name01"
"code01"
"version01"

How can I get the name property without double quotaions, here is name01, it is the first parameter in the function. It only appears after the Process keyword.

Edit1: In my first quesiton, the both patterns (?<=Process\(")[^\r\n"]* and \bProcess\("([^"]+)"[^()]*\) work for the case. Thanks.

Edit2: It happens that another requirment to retrieve the all 3 arguments of the process function from the text script below:

var f = pmb.Process("name01", "code01", "version01") .Task("name01", "code01");

I need to get the process function argument:

name01
code01
version01

And dont need the task function argument. Firstly(Thanks the Fouth Bird),

\bProcess\([^()]*\)

This only matched Process("name01", "code01", "version01"), should I use the second pattern to filter it to get the 3 arguments? Thanks!

2 Answers 2

2

Maybe,

(?<=\(")[^\r\n"]*

or

(?<=Process\(")[^\r\n"]*

might be OK to look into, I guess, if lookbehind is supported.

RegEx Demo 1

RegEx Demo 2


If you wish to simplify/update/explore the expression, it's been explained on the top right panel of regex101.com. You can watch the matching steps or modify them in this debugger link, if you'd be interested. The debugger demonstrates that how a RegEx engine might step by step consume some sample input strings and would perform the matching process.


RegEx Circuit

jex.im visualizes regular expressions:

enter image description here

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

Comments

2

There is no need to use a positive lookbehind as the only thing missing from your pattern to match the first value between double quotes is prepending an opening parenthesis:

\("([^"]+)"
^^
  • \(" Match ( and "
  • ( Capture group 1
    • [^"]+ Match 1+ times any char except "
  • )" Close group and match "

The value is in the first capturing group.

Regex demo


If you also want to make sure that there is a closing parenthesis and that is starts with Process:

\bProcess\("([^"]+)"[^()]*\)

Regex demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.