• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to write a regular expression which has two letters separated by comma and specific combination

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to write a regular expression which has two letters separated by comma and specific combination will not allowed other than everything will allow.



I have a string 700XXX(5b,c). In this string XXX can be any letters and (5b,c) will not allowed to match but combination of e.g

700XXX(5a-z,c) except 'b' is not allowed e.g 700XXX(5d,c),700XXX(5f,c) is allowed like that

700XXX(5b,a-z) except 'c' is not allowed e.g 700XXX(5b,a), 700XXX(5b,k) is allowed like that

Can anybody help me to write regular expression for this string?
 
Marshal
Posts: 64687
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Do you mean that is there is a b before the comma, you are now allowed b after the comma. That looks like a context‑sensitive grammar which can never be expressed with a regular expression.
 
Campbell Ritchie
Marshal
Posts: 64687
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you mean without the c independent of what is before the comma, that is probably quite easy to write with a regex. Please show us what you have tried.
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell is obviously much more astute than I am because having read the OP at least 5 times I still don't have a clue what the requirement is! I really don't understand how the terms such as "(5d,c)" are meant to constrain the XXX values; I'm not even sure they are meant as a constraint!
 
Campbell Ritchie
Marshal
Posts: 64687
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Richard Tookey wrote:Campbell is obviously much more astute than I am . . .

Or he was simply guessing
 
Campbell Ritchie
Marshal
Posts: 64687
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Earlier, I wrote: . . . Do you mean that is there is a b before the comma, you are now allowed b after the comma. . . .

Surely that should have said “not allowed”?
 
Ranch Hand
Posts: 235
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea how applicable This is, but it provides a (very) short example on validating the British postal code, using regular expression, which has a very unique and distinct format. HIH
 
Campbell Ritchie
Marshal
Posts: 64687
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends whether the text permitted is like a postal code; you can live at Aberdeen and have a postal code AB1 1AB. If using AB before the numbers would preclude using AB afterwards, then a regex would probably be impossible to create.
 
lowercase baba
Posts: 12751
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My thoughts are "Why do you think a regex is the way to do it?" I don't know if it is or not, but any time someone says "How do I use tool X to do Y?", it makes me think that you may be trying to drive a screw in with a hammer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!