Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  help with reg expression  (Read 427 times)
0 Members and 2 Guests are viewing this topic.
Offline Kommi

Sr. Member
**

Posts: 293


All opinions will be lined up and shot!


« on: 2006-01-31 17:37:43 »

I am trying to write a reg expression with the following rules:
Must start with a lower case letter, can have any characters in between EXCEPT NUMBERS, must end with a lower case letter

the expression I came up with is the following:
1  
[a-z]+([^0-9]*?)[a-z]+


the problem is that "section9" will yeild "section", and "se-ction9" will yeild "se-ction". But "se1ction9" will break it down into 2 mathces, "se" and "ction". How can I change my expression so that "se1ction9" is rejected completely?

Kommi
Offline swpalmer

JGO Kernel
*****

Posts: 3438
Medals: 4


Where's the Kaboom?


« Reply #1 on: 2006-01-31 17:47:02 »

I don't think you need the '?' in your example.

I always use this site http://www.regular-expressions.info/tutorial.html as a reference when I'm trying to grok regular expressions.

I think you just need to add beginning of line and end of line markers to what you have

1  
^[a-z]+([^0-9]*?)[a-z]+$


http://www.regular-expressions.info/anchors.html

see also http://www.regular-expressions.info/wordboundaries.html if you are matching this inside a longer string.

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.078 seconds with 19 queries.