S X
S X

Reputation: 19

regex grab a word

i'm trying to grab a regex from source, but only name from this type.

"name":"HELP-PERP","posOnly":false,"price":40.3,"priceIncrement":0.01,"quote":null,"quoteV":73851918.483,"restricted":false,"sizeIncrement":0.01,"type":"future",

So i got here \b(\w*-PERP\w*)\b

This grabs the word HELP-PERP but duplicates it, so i'm trying to grab that word that matches the type =future.

Grab help-perp that is in the same line with type":"future".

Total nub at this, i've tried several things on regex101 and can't come up :(

Thank you

Upvotes: 1

Views: 41

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626689

You can use

/\w*-PERP\w*\b(?=.*type":"future")/g

See the regex demo.

Details

  • \w*-PERP\w* - zero or more word chars, -PERP, and again zero or more chars
  • \b - a word boundary
  • (?=.*type":"future") - a positive lookahead that matches a location in string that is immediately followed with any zero or more chars other than line break chars as many as possible (.*) and then a type":"future" string.

Upvotes: 1

Related Questions