• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex for allowing alpha characters and wildcard %  RSS feed

 
Mary Joe
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need a regular expression for checking on a name String

It should contain only alpha characters and wildcard %
Eg: %Joh%

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I need a regular expression for checking on a name String

post what you've tried,
we'll see if we can add the extras
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.regex.Pattern. I suggest you start by reading its Javadoc.
 
paul wheaton
Trailboss
Posts: 22580
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to understand what you are looking for. Are you wanting to fish a substring out? Are you wanting to know the boolean: match or not match?

Can you give some examples of strings that are a match and strings that are a fail?

For me, I find that anytime I do regex, I first write a ton of unit tests because I really think regex is a breeding ground for bugs.



 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please see ShowSomeEffort and NotACodeMill --everyone here is willing (dare I say eager) to help, but the likelihood of just getting a "ready-made" answer is pretty low :) Showing us what you've tried so far is also encouraged.

Welcome to JavaRanch!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I write regular expressions, I always start small and build it up.

Do you know how to:
match a single alpha character
match a %
match multiple alpha characters

Also, can the % be anywhere in the string or just the beginning/end?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!