...
For example, suppose you want to find the value from the following snippet:
No Format |
---|
input type="hidden" name="secret" value="CAFEBABE.12345(3)"
|
...
If not, examine the expression for any meta-characters (characters that have a special meaning in regexes).In this case, the only special characters are the "." and the parentheses "(" and ")".These need to be escaped, by being prefixed with "\". We now have:
No Format |
---|
input type="hidden" name="secret" value="CAFEBABE\.12345\(3\)"
|
...
So assume you want to match just
No Format |
---|
CAFEBABE.12345
|
Your regular expression then becomes:
No Format |
---|
input type="hidden" name="secret" value="(CAFEBABE\.12345)\(3\)"
|
...
A digit is easy, that's "\d
", so a number is "\d+
", where the "+
" means one or more of the previous item.
...
A
...
hex
...
character
...
can
...
be
...
represented
...
by
...
"
...
[0-9A-Za-z
...
]
".
...
The
...
enclosing
...
"
...
[
...
]
"
...
create
...
a
...
character
...
class
...
which
...
matches
...
one
...
of
...
the
...
specified
...
characters.
...
The
...
"-
"
...
here
...
means
...
a
...
range
...
So putting that together, we get:
...
No Format |
---|
input type="hidden" name="secret" value="([^"]+)" |
Wiki Markup |
The
...
character
...
class
...
in
...
this
...
case
...
is
...
[^"
...
]
...
which
...
means
...
any
...
character
...
except
...
double-quote.
...
The
...
"+
"
...
suffix
...
means
...
we
...
want
...
as
...
many
...
as
...
there
...
are
...
in
...
succession.
...
This
...
will
...
take
...
us
...
up
...
to
...
the
...
end
...
of
...
the
...
value.
Hints and tips
If the expression matches more than once in the source, you have a choice:
...