0

I want to create a regex which will match string like "123;qwe;12324", this regex is working fine:

[a-zA-Z0-9;]

But I want to allow blank spaces also if preceded or followed by ; but this is not working:

[a-zA-Z0-9;\s(?=;)]

Can someone please help.

1
  • You say "spaces", maybe you need \s* ? Commented Aug 12, 2014 at 9:35

1 Answer 1

2

I guess

/^([a-zA-Z0-9]+\s*;\s*)*[a-zA-Z0-9]+$/

Test

> re.test('abc')
true
> re.test('abc;def')
true
> re.test('abc;  def')
true
> re.test('abc;  def;')
false
> re.test('abc^^^;  def;')
false
Sign up to request clarification or add additional context in comments.

2 Comments

re.test('abc; def;') should also be a valid string for me...please help
@JyotiPuri: try adding ;? to the end

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.