• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regular Expression Question

 
Ranch Hand
Posts: 111
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"^[a-zA-Z]*$"
"^[A-Z]\\d[A-Z]\\d[A-Z]\\d$"
Can any one give me some sample examples about these regular expressions.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sanat kumar,

As far as i know,

"^[a-zA-Z]*$" ---- means an expression starts with a,b,c...z or A,B,C..Z
example, a
Aa
AasdfZadsf


"^[A-Z]\\d[A-Z]\\d[A-Z]\\d$" --- means [A-Z] single char between A,B..Z
\\d means 0,1,...9 any on char

like that "B3E3S1". Note that here not * is given it mean only on char.

to represent "SLFDJLK3alsdkjf" or "KHDJKFHJK3" in regular expression use

^[A-Z]*\\d[a-z]*$ --- starts with zore or more capitals, there should be one digits after that zero or more small alphabets.

Hope this helps you.

All The Best
 
sanat
Ranch Hand
Posts: 111
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks sasi kala for your quick reply.
 
sanat
Ranch Hand
Posts: 111
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

What are the characters ^ and $.

Can anyone give a validation rule for email ids.

Thanks in advance.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I downloaded a tool called RegEx Coach. It has a free trial period but you may find you want to pay for it. When you highlight part of an expression it gives a plain English description. It's neat to work interactively with a tool like that while learning regular expressions.

One note: That particular tool is not 100% compatible with Java's regex. Plus you have to add escape characters in Java. Google for regular expression tools in Java for more. There is one that works as an Eclipse plugin if that sounds useful.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Pattern class javadoc will help you with regex expressions.

^ means not
$ means end of line
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to clear this up:

^ matches the beginning of the line, however, when its inside a character class (i.e. [^a-z]) it means 'not'.

Therefore: ^[a-zA-Z] would be mean 'match any uppercase or lowercase letter at the beginning of a line'.

$ matches the end of a line

* means 'match 0 or more occurances of the preceding character'.

Therefore:

^[a-zA-Z]*$ means: Match a string that starts with 0 or more characters that are either uppercase or lowercase. The string must consist fully of letters.

The following would match:

Robert
Ivor
Lofthouse

The following wouldn't match:

Robert3#
Ivo1r
2Lofthouse@
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic