1

Need to construct regexp to this

2 1231 21231 2312 2123 22 2

Need to find only 2, not 1231, not 21231, only 2

So, my regexp is

^[[:digit:]]?{1}[2]{1}^[[:digit:]]?

Is it right ?

Sorry if my ask like a 'do it for me', but i really cannot into regexp.

UPD
input string 2 22 1312 123123 22312 21 2
need to match "2"
2 22 1312 123123 22312 21 2
with or w\o digits after\before

3
  • Could you elaborate a bit more? Is this meant to be one long string or multiple strings to be tested? Try to write it like input: "12 34" and output: "2", possibly using some character to find that's not ambiguous. Commented Apr 13, 2012 at 11:31
  • input string 2 22 1312 123123 22312 21 2 need to match "2" 2 22 1312 123123 22312 21 2 with or w\o digits after\before Commented Apr 13, 2012 at 11:34
  • why are you using regexp in that case? Commented Apr 13, 2012 at 11:37

1 Answer 1

1

Sounds simple enough...

/\b2\b/g

How about this one? Example

Sign up to request clarification or add additional context in comments.

1 Comment

How could i use this in Mysql query? While selecting a column i hav e to select individual number like this, how could i achieve this? SELECT * FROM table WHERE table_id REGEXP /(/\b2\b/)/g;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.