• Post Reply Bookmark Topic Watch Topic
  • New Topic

what does this Pattern statement mean?  RSS feed

 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across the code line



what does this code mean?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the API for the Pattern class to see what the compile method does? That should be your first step.

Then if you have specific questions, come back. We expect you to ShowSomeEffort (<--click that link).
 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My assumption is it will first search for A-Z then a-z and after that it will search for 0 to 9 and after that ., - and whitespace.

Please Correct me if I am wrong.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so your question is actually more about what the pattern means, not what the line of code means?

Generally it is best to break down any regular expression piece by piece.

So, for starters, the square brackets define a 'chunk' of stuff. The plus after it means that you have to have one or more of whatever is inside the brackets.

then you start looking at what is inside the brackets to see what that means...Try searching for a regex tutorial. It should explain most of this.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:So, for starters, the square brackets define a 'chunk' of stuff. The plus after it means that you have to have one or more of whatever is inside the brackets.

then you start looking at what is inside the brackets to see what that means...Try searching for a regex tutorial. It should explain most of this.


Well, you probably need to also understand what the brackets themselves mean. It's not just a "chunk", it's something called a character class. And the rules for how you interpret stuff inside a character class are somewhat different from interpreting things outside of a character class. So focus on the parts of tutorials that talk about character classes, or that show braces [ ] in their examples.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:Well, you probably need to also understand what the brackets themselves mean. It's not just a "chunk", it's something called a character class. And the rules for how you interpret stuff inside a character class are somewhat different from interpreting things outside of a character class. So focus on the parts of tutorials that talk about character classes, or that show braces [ ] in their examples.

Thanks for clarifying that. I was sort of implying that with the 'look inside the brackets and see what that means', but I agree it wasn't as clear as your explanation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!