Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   regex reserved chars (http://www.velocityreviews.com/forums/t957357-regex-reserved-chars.html)

Roedy Green 02-07-2013 12:28 AM

regex reserved chars
 
I have always treated $ ( ) * + -. ? [ \ ] ^ { | }
as reserved regex chars.
I can't find any docs that say the list is different inside[ ].
is it?
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law

markspace 02-07-2013 12:54 AM

Re: regex reserved chars
 
On 2/6/2013 4:28 PM, Roedy Green wrote:
> I have always treated $ ( ) * + -. ? [ \ ] ^ { | }
> as reserved regex chars.
> I can't find any docs that say the list is different inside[ ].
> is it?
>


<http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html>

"Note that a different set of metacharacters are in effect inside a
character class than outside a character class. For instance, the
regular expression . loses its special meaning inside a character class,
while the expression - becomes a range forming metacharacter. "

Learn to STFW.

I really hate to use language like that, but Jesus Roedy are you kidding me?




Arne Vajhøj 02-07-2013 01:18 AM

Re: regex reserved chars
 
On 2/6/2013 7:28 PM, Roedy Green wrote:
> I have always treated $ ( ) * + -. ? [ \ ] ^ { | }
> as reserved regex chars.
> I can't find any docs that say the list is different inside[ ].
> is it?


Typical it is.

Regex syntax vary a bit between implementations.

So one should study the documentation.

java.util.regex.Pattern has an excellent JavaDoc.

Read it!

Arne



Lew 02-07-2013 02:03 AM

Re: regex reserved chars
 
markspace wrote:
> Roedy Green wrote:
>> I have always treated $ ( ) * + -. ? [ \ ] ^ { | }
>> as reserved regex chars.
>> I can't find any docs that say the list is different inside[ ].
>> is it?

>
> <http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html>
>
> "Note that a different set of metacharacters are in effect inside a
> character class than outside a character class. For instance, the
> regular expression . loses its special meaning inside a character class,
> while the expression - becomes a range forming metacharacter. "
>
> Learn to STFW.
>
> I really hate to use language like that, but Jesus Roedy are you kidding me?


http://lmgtfy.com/?q=Regular+express...haracter+class

HTH

--
Lew

markspace 02-07-2013 02:10 AM

Re: regex reserved chars
 
On 2/6/2013 6:03 PM, Lew wrote:

> markspace wrote:
>> Learn to STFW.
>>
>> I really hate to use language like that, but Jesus Roedy are you kidding me?


>
> http://lmgtfy.com/?q=Regular+express...haracter+class



My point was that Roedy is a Java programmer post in a Java newsgroup,
and he didn't even look at the existing Java docs for regex patterns. I
just can't even conceive why Roedy would post such a question. I wasn't
even going to post the lmgtfy link because the Java docs are such an
obvious solution.

That said the first link when I do Google is a really excellent
discussion exactly how character classes and meta-characters work, with
even different flavors of regex discussed (Posix is a bit different, the
others seem the same.)



Roedy Green 02-07-2013 06:50 AM

Re: regex reserved chars
 
On Wed, 06 Feb 2013 18:10:45 -0800, markspace
<markspace@nospam.nospam> wrote, quoted or indirectly quoted someone
who said :

>My point was that Roedy is a Java programmer post in a Java newsgroup,
>and he didn't even look at the existing Java docs for regex patterns


I spent 15 minutes looking and did not find it. You can argue that I
should have, but the fact remains I did not. I did you no harm by
asking a question. You are not obligated to answer it. The answer
may be of general interest to people who never even thought to ask the
question. If I asked you face to face you would not dream of
answering that way.

The problem is too MUCH irrelevant crap you have to wade through when
you search.

The answer to many such a question is simply the magic vocabulary that
evokes the desired info. But you have to find the information to know
the magic vocabulary. Catch 22.
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law

Roedy Green 02-07-2013 07:06 AM

Re: regex reserved chars
 
On Wed, 6 Feb 2013 18:03:56 -0800 (PST), Lew <lewbloch@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>p://lmgtfy.com/?q=Regular+expression+metacharacters+character+cla ss


Did you check to see if the question is actually answered in there
somewhere, or just that in any sane universe it should be?


Some of that material I previously waded through without success.

This question may be easier to answer with a set of experiments.
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law

Roedy Green 02-07-2013 07:31 AM

Re: regex reserved chars
 
On Wed, 06 Feb 2013 16:28:29 -0800, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>ve always treated $ ( ) * + -. ? [ \ ] ^ { | }
>as reserved regex chars.
>I can't find any docs that say the list is different inside[ ].


I have not found an official source however it is claimed only [ - ^]
are reserved in character classes i.e inside [...]

I don't think that can be right. Surely $ is reserved too, and of
course \.
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law

Robert Klemme 02-07-2013 12:38 PM

Re: regex reserved chars
 
On Thursday, February 7, 2013 8:31:47 AM UTC+1, Roedy Green wrote:
> On Wed, 06 Feb 2013 16:28:29 -0800, Roedy Green
>
> <see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
> someone who said :
>
> >ve always treated $ ( ) * + -. ? [ \ ] ^ { | }
> >as reserved regex chars.
> >I can't find any docs that say the list is different inside[ ].

>
> I have not found an official source however it is claimed only [ - ^]
> are reserved in character classes i.e inside [...]


Is http://docs.oracle.com/javase/6/docs...x/Pattern.html not official enough? Or are you missing an more explicit explanation on that page?

> I don't think that can be right.


Roedy, why???

> Surely $ is reserved too, and of course \.


Dot has no special meaning and neither does $. Btw. you can easily test that. Apart from that dot with special meaning does not make sense in a character class if you think about it for a moment.

Cheers

robert

markspace 02-07-2013 05:32 PM

Re: regex reserved chars
 
On 2/6/2013 10:50 PM, Roedy Green wrote:
> On Wed, 06 Feb 2013 18:10:45 -0800, markspace
> <markspace@nospam.nospam> wrote, quoted or indirectly quoted someone
> who said :
>
>> My point was that Roedy is a Java programmer post in a Java newsgroup,
>> and he didn't even look at the existing Java docs for regex patterns

>
> I spent 15 minutes looking and did not find it. You can argue that I
> should have, but the fact remains I did not.


I really am not trying to be an ass (there's enough of that here
already). But seriously I'm not kidding when I say the answer is
literally the first link when I search.

<https://www.google.com/search?q=regex+character+class>

What the FIRST link when you use that search?

> I did you no harm by
> asking a question. You are not obligated to answer it. The answer
> may be of general interest to people who never even thought to ask the
> question.


"STFW" is the answer, and it's of general interest. C.f. Eric Raymond's
"How to Ask Questions the Smart Way," which says the same thing.

> If I asked you face to face you would not dream of
> answering that way.


I certainly might. Learning how answer your own questions is part of
your professional development; don't waste your colleagues' time with
silly questions. There's a Dilbert cartoon about "time wasting morons."
It's funny because "time wasting morons" are common enough to have a
Dilbert about it. Don't be the time wasting moron.

> The problem is too MUCH irrelevant crap you have to wade through when
> you search.


Not when I search, and so I have to conclude the same is true for you.

>
> The answer to many such a question is simply the magic vocabulary that
> evokes the desired info. But you have to find the information to know
> the magic vocabulary. Catch 22.
>


You used all the words you needed in your question. What "magic
vocabulary" are you referring too? I get on your case Roedy because I
know you've got enough experience that you should know these things already.






All times are GMT. The time now is 06:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57