0

I need to pull out of a this string of characters after $

($Q1==1)and($Q4o=="55")and($Q1o1=="")

I mean these $Q1, $Q4o, $Q1o1

As I understand, the regular expression should start searching from $ and end on any character except A-Za-z0-9_. Can you help me write the regex?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Denis
  • 2,429
  • 5
  • 33
  • 61
  • 2
    Please elaborate on your use case. Are you trying to parse PHP code, or a subset thereof? (Then the tokenizer might be simpler.) * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Nov 15 '12 at 15:34
  • Where are you stuck? Have you tried to come up with one on your own yet? Here's a hint: in regex, `$` means "end of string", so you'll need to escape it: `\$`. – gen_Eric Nov 15 '12 at 15:35
  • 1
    What is the regular format you're looking to match? Is it always `$Q` followed by something random, or are the more specific rules in place? – LeonardChallis Nov 15 '12 at 15:35
  • no, $Q1 is not a variable, simple string i know a theory of regex, but always fails in real :( – Denis Nov 15 '12 at 15:37

2 Answers2

4

This seems to work, at least in Ruby:

/\$\w*/

Be careful with the $, as $ is a reserved symbol in regular expressions that means "end of the string", so you need to escape it.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Gonzalo Quero
  • 3,303
  • 18
  • 23
0

/\$([[:alnum:]]+)[[^:alnum:]]/

You'll want to pull out the first bracketed expression.

EDIT: I prefer the other suggestion, using \w*

Keith
  • 54
  • 3