Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Regex: Any character in character class

Reply
Thread Tools

Regex: Any character in character class

 
 
Sebastian
Guest
Posts: n/a
 
      01-30-2013
I want to match any sequence of characters, including line breaks, in a
suffix of a multi-line string.

I do not want to use Pattern.DOTALL, because line breaks are not
permissible everywhere. I cannot write [.]* because dot loses its
special meaning inside a character class.

I have come up with [\S\s]*
as meaning any sequence of non-whitespace or whitespace (incl.
line-breaks). Is there a better way?

-- Sebastian

 
Reply With Quote
 
 
 
 
Mikhail Vladimirov
Guest
Posts: n/a
 
      01-30-2013
What about [^]?
 
Reply With Quote
 
 
 
 
Mikhail Vladimirov
Guest
Posts: n/a
 
      01-30-2013
Another option is .|\n
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      01-31-2013
On 1/30/2013 5:05 AM, Mikhail Vladimirov wrote:
> What about [^]?


java.util.regex.PatternSyntaxException

Arne


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      01-31-2013
On 1/30/2013 4:34 AM, Sebastian wrote:
> I want to match any sequence of characters, including line breaks, in a
> suffix of a multi-line string.
>
> I do not want to use Pattern.DOTALL, because line breaks are not
> permissible everywhere. I cannot write [.]* because dot loses its
> special meaning inside a character class.
>
> I have come up with [\S\s]*
> as meaning any sequence of non-whitespace or whitespace (incl.
> line-breaks). Is there a better way?


Do you always want to accept line breaks or not? If not then when?

Arne


 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      02-01-2013
On 01/30/2013 11:27 PM, Arne Vajh°j wrote:
> On 1/30/2013 4:34 AM, Sebastian wrote:
>> I want to match any sequence of characters, including line breaks, in a
>> suffix of a multi-line string.
>>
>> I do not want to use Pattern.DOTALL, because line breaks are not
>> permissible everywhere. I cannot write [.]* because dot loses its
>> special meaning inside a character class.
>>
>> I have come up with [\S\s]*
>> as meaning any sequence of non-whitespace or whitespace (incl.
>> line-breaks). Is there a better way?

>
> Do you always want to accept line breaks or not? If not then when?
>
> Arne
>
>

Good question.

I take it the suffix is a generic last-N characters of the string
(Assumption #1). I take it that line breaks are OK in the suffix, not
necessarily so in the rest of the string (Assumption #2).

If you don't mind me asking, why don't you just grab the suffix, the
last N characters, with substring()? That *is* your match.

AHS
 
Reply With Quote
 
Sebastian
Guest
Posts: n/a
 
      02-01-2013
Am 31.01.2013 04:27, schrieb Arne Vajh°j:
> On 1/30/2013 4:34 AM, Sebastian wrote:
>> I want to match any sequence of characters, including line breaks, in a
>> suffix of a multi-line string.
>>
>> I do not want to use Pattern.DOTALL, because line breaks are not
>> permissible everywhere. I cannot write [.]* because dot loses its
>> special meaning inside a character class.
>>
>> I have come up with [\S\s]*
>> as meaning any sequence of non-whitespace or whitespace (incl.
>> line-breaks). Is there a better way?

>
> Do you always want to accept line breaks or not? If not then when?
>
> Arne
>
>

the string I want to match basicallyhas two parts (a "protocol" and a
"selection expression"). I want to allow line breaks anywhere in the
selection expression, but not in the protocol.
-- S.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      02-01-2013
Sebastian wrote:
> the string I want to match basicallyhas two parts (a "protocol" and a
> "selection expression"). I want to allow line breaks anywhere in the
> selection expression, but not in the protocol.


How do you tell which part is which?

--
Lew

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      02-01-2013
On 2/1/2013 3:14 PM, Sebastian wrote:
> Am 31.01.2013 04:27, schrieb Arne Vajh°j:
>> On 1/30/2013 4:34 AM, Sebastian wrote:
>>> I want to match any sequence of characters, including line breaks, in a
>>> suffix of a multi-line string.
>>>
>>> I do not want to use Pattern.DOTALL, because line breaks are not
>>> permissible everywhere. I cannot write [.]* because dot loses its
>>> special meaning inside a character class.
>>>
>>> I have come up with [\S\s]*
>>> as meaning any sequence of non-whitespace or whitespace (incl.
>>> line-breaks). Is there a better way?

>>
>> Do you always want to accept line breaks or not? If not then when?


> the string I want to match basicallyhas two parts (a "protocol" and a
> "selection expression"). I want to allow line breaks anywhere in the
> selection expression, but not in the protocol.


Do you have a separator between the two parts like colon in URL's?

If yes then something like:

[.]+:[.|\n]+

Arne


 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      02-01-2013
On 2/1/2013 1:47 PM, Arne Vajh°j wrote:

> [.]+:[.|\n]+



Watch out for this. +, being greedy, will match a : in the selection
expression (the 2nd part) if : is allowed in the second part.

The reluctant modifier might be a better idea here:

..+?:[.|\n]+

Note that I don't think the initial brackets [] were needed. Also we're
yet again starting to see the problem with regex: it always evolves into
something that looks like your cat walked across the keyboard.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
pointer to any member function of any class joosteto@gmail.com C++ 6 07-12-2006 05:29 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM



Advertisments