5

I have a statement like Data lva_var type Integer value 20. I need to find out the token after type.

My latest try was [type](?:\s\S+), but the match was e integer.

Code snippets would be helpful.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
AKHIL RAJ
  • 78
  • 1
  • 2
  • 4

3 Answers3

7

Just try this,
type\s(\w+)
Here the first group contains the word next to "type"
Hope this code helps.

Karthikeyan KR
  • 1,134
  • 1
  • 17
  • 38
  • It should not match the word 'type', it must just match a word after it excluding that word. – AKHIL RAJ Sep 09 '16 at 13:33
  • The parentheses will capture the word after 'type' separately. See this for how to get it: http://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression – adam0101 Sep 09 '16 at 13:34
  • @AKHILRAJ as Adam mentioned the parentheses will capture your token as a seperate group. – Karthikeyan KR Sep 09 '16 at 13:37
3

You can use lookbehind for this (?<=\btype\s)(\w+) will do the trick for you. Take a look at this example.

Stefan.B
  • 136
  • 1
  • 5
  • Please view edited answer, code was included in the provided link ( as it still is ). – Stefan.B Sep 09 '16 at 13:52
  • 2
    Thanks. Just helping you understand "best practices". If the link ever breaks, that service ever goes away, etc, your code would be lost. Further, having the code in your answer saves future visitors time. Thank you! – random_user_name Sep 09 '16 at 15:19
2

JavaScript doesn't support lookbehinds, but since you tagged nsregularexpression and that does support them, maybe try this: (?<=\btype\s+)\w+

adam0101
  • 29,096
  • 21
  • 96
  • 174