• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regex lookahead question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is basically a general regex question tho I'm using the Java-flavor of it.
I'm parsing a file containing variables wich are denoted by $name. I need to find all the variables for later use. However one syntax gives me a problem:
$varName in $varList
Here I only wish to match $varList. I've tried to use a negative lookahead like so:

The only effect this has is, quite logicaly, that the last w+ before a " in" isnt matched, ie my matches would be $varNam and $varList. How do I solve this? Theres probably some stupidly easy way but I just cant see it!
Thanks
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One option is to add a "word boundary" to the regex. This will force the match to match the whole word, and not allow it to backup one letter to avoid the "in" word.

Henry
 
David Lindahl
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A very simple and working solution, thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic