• Post Reply Bookmark Topic Watch Topic
  • New Topic

regex, what does this means->  RSS feed

 
Costa lamona
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

"^\\d{12}$" what does this pattern means

don't direct me to some tutorial, I know what is it, but I am making sure about what I had conclude.

Thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you tell us what you have concluded so that we can chime in on that?
 
Costa lamona
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to mislead you so you say, yah you are right.
and don't be suspecious . I know it does not make any sense to ask about such simple stright forword pattern, but It will make a sense if you don't know what is ^, I just guess it is "not".
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^ is not "not" when used at the beginning of a regexp. It can have that meaning when used inside of a character class like "[...]", but not in this case. This page may help make things clearer.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually (based on Ulf's link)
^ is the start of the line
$ is the end of the line
\\ is the backslash character
d is a 'd'
{12} means exactly 12 of something

Put them together and you get...
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

\\ is the backslash character
d is a 'd'


I think this might be pointing in the wrong direction. While it is correct when interpreting the regexp literally, I am guessing that this is coming out of a Java String, which has its own rules about backslashs: Two backslashes in a String would mean a single actual actual one, which would then escape the "d". Hence, not a literal backslash and then a literal "d", but a "\d". What that means is also explained on the page I linked to.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!