SheppardDigital
asked on
Regular expression help
Hi,
Should be an easy one for someone that understands regular expressions.
I have the text...
(123) products
I need a regular expression that will return the number within the brackets, this number could be any length, ie.1 or 12345
Should be an easy one for someone that understands regular expressions.
I have the text...
(123) products
I need a regular expression that will return the number within the brackets, this number could be any length, ie.1 or 12345
This match beginning of a line follow with a open parentheses. Capture any number of digits. Match a close parentheses and anything afterward.
^\((\d+)\).+$
ASKER
Hi,
Sorry, I forgot to mention I also need to match it against the word products.
"(123) products"
I need to detect "(?) products" and have it return the value of ?
Sorry, I forgot to mention I also need to match it against the word products.
"(123) products"
I need to detect "(?) products" and have it return the value of ?
^"\((\d+)\).+"$
\((\d+)\) products
Try this pattern:
Which language are you using?
\((\d+)\) products
The number will be captured as the first group. There are different ways of getting the value, depending on the language.Which language are you using?
I'm still reading up on this, but the most common way I've seen thus far is $1 or \1 to grab the first capturing group (or the first outermost group, if you've got nested parens).
ASKER
Hi,
bigdogdman, your suggestion kind of works, but when I've applied it to the actual text it's not working.
The text I'm looking for is in the middle of some HTML, but it's returning no results, however if I just apply it to the text '(123) products' then its works fine, but in reality the line of text I'm trying to pull from is 'Toys (123) products'
I'm using PHP by the way.
bigdogdman, your suggestion kind of works, but when I've applied it to the actual text it's not working.
The text I'm looking for is in the middle of some HTML, but it's returning no results, however if I just apply it to the text '(123) products' then its works fine, but in reality the line of text I'm trying to pull from is 'Toys (123) products'
I'm using PHP by the way.
ASKER
ah sorry, my mistake.
The text I'm actually trying to find is
(123 products)
and not
(123) products
The text I'm actually trying to find is
(123 products)
and not
(123) products
\((\d+)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
pls try
Open in new window
Regards