2

I am trying to get string using RegEx; here is the string:

window.runParams = {};
window.runParams = {blablabla};

How to get the second string {blablabla}? I am using REGEX:

(?<=window.runParams = ").*(?=;)

But that gets the first string {}.

3 Answers 3

1
  1. If you want to get string with braces eg: {blablabla}

    window.runParams = ({\w+})

  2. If you want to get only the string inside braces eg: blablabla

    window.runParams = {(\w+)}

Value of group 1 is your result

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

Comments

0

The following pattern captures only curly brackets with word character content:

(?<=window.runParams = ){\w+}(?=;)

and will only capture:

{blablabla}

when run against the text:

window.runParams = {};
window.runParams = {blablabla};

See results here:

https://regex101.com/r/mTwA64/1

Comments

0

try modifying your regex so it only accepts matches with non-empty curly brackets \{.+\} such as

(?<=window\.runParams = )(\{.+\})(?=;)

...there's probably ways to simplify the regex further, depending on you problem...my guess is you don't need the lookahead/lookbehind, e.g. in the example given \{.+\} will do just fine (returns {blablabla}) ....but it really depends on the format and content of your file...also remember braces, dots etc have a special meaning in regexes so you probably would want to escape them

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.