BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expressions Board

Spoiler

**EDIT 2** : LOL, Lithium forum parser, you're so silly when it comes to curse words and special character sequences

There is definitely something emotionally resonant about seeing a sad-smiley in the middle of a long regex. 🙂

Message 121 of 150
(6,589 Views)
 
Spoiler
**EDIT 2** : LOL, Lithium forum parser, you're so silly when it comes to curse words and special character sequences

Maybe the issue here is that the parser is using a regex? Smiley Very Happy

0 Kudos
Message 122 of 150
(6,550 Views)

Maybe we could ask for a Verbose field in the Lithium editor to identify sections of text not to be interpreted. We have an "insert code" toolbar item, which I've never used. Here's a test of Jack's reg ex that created an emoticon in the middle:

 

(?:/s*)?(?<!\\)"(.*?)(?<!\\)"(?:/s*)??:/s*)?(?<!\\)"(.*?)(?<!\\)

 

Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 123 of 150
(6,523 Views)

If you go into your profile settings, then Preferences, then Display, change the setting for the Emoticon Type from Default to None.

 

Now you won't see the automatic emoticons.

Message 124 of 150
(6,513 Views)

hello,

 

How to have the "opposite" of a reference ?

 

(sorry for my bad english, i do my best)

 

(3)[^3] matches "32", "3a" ...

 

I would like to replace the second term < [^3] > by a reference to the first term < (3) >   ....   ...\1 instead of [^3]

 

The problem is the " ^ " ... and obviously, (3)[^\1] does not work !

 

in other words, all except  " \1 "

 

is there a way to do that ?

 

Thanks to all,  ( x )

0 Kudos
Message 125 of 150
(6,488 Views)

@ouadji wrote:

hello,

 

How to have the "opposite" of a reference ?

 


Yo, ouadji -- check out Negative Lookaheads, and the following regex:

 

(3)(?!\1)

 

The way to read this entire regex is:

  • Match the literal '3', storing it into a backreference
  • Ensure that the following characters are not equal to what's in the backreference -- in our case of a simple literal, '3'

I have a suspicion this regex is not sufficient for what you're needing -- if that's the case, can you provide more test vectors of inputs and expected outputs? Or, if this nudges you in the right direction, reply with the final regex you implement! Thanks!

Message 126 of 150
(6,517 Views)

thank you Jack

 

(3)(?!\1) ... good idea ...

 

but,

 

with an input string " 3313 ", this expression matches " 3 " .. this is not the result I would like to get.

 

i would like to have " 31"

 

the second term is just a condition of matching!,
and the second character is not included in the match.

 

(3)(?(?!\1).|^)  works ! (it's my best-shot, I have not yet found a better way!)

 

if the next character is not equal to "3", THEN "this character" ... else 'start of the line" ("start of the line" is an impossible condition)

 

SR3.png

 

(again, sorry for my bad english, it's not easy for me)

0 Kudos
Message 127 of 150
(6,507 Views)

I sent a  feature request  to the author of PCRE
Except in the special case of "character classes",
PCRE has no general character to get "the opposite of".

I think this is a gap, it should be possible to get (easily) the opposite of a reference.

for exemple, just a idea, why not like this : ~\n

0 Kudos
Message 128 of 150
(6,499 Views)

@JackDunaway wrote:
Looks like nothing a couple lookarounds as zero-width assertions can't handle.

 

Try (?<=\[ABC\]\[)(.*?)(?=\]) with the Search and Replace String Node, ensuring to turn on Regular Expression matching via it's right-click menu option.

 

SearchAndReplaceWithLookarounds.png


One deficiency of Lookbehinds is the inability to declare a variable-width match. (Lookaheads, on the other hand, allow variable-width matches)

 

Notice in the quoted snippet, the lookbehind is looking for a fixed-width match -- [ABC][

 

What happens, for instance, if our application domain does not allow us to constrain the lookbehind as fixed-width?

 

Try replacing the Lookbehind with the escape sequence \K which excludes everything preceding from the whole match.

 

The original regex (?<=\[ABC\]\[)(.*?)(?=\]) could be rewritten as \[ABC\]\[\K(.*?)(?=\])

 

To make that original regex even more powerful for matching any arbitrary variable-width value inside the initial braces, we could write this as: \[.*?\]\[\K(.*?)(?=\])

 

And to take it one step futher if necessary, add a capturing group to grab the arbitrary value inside the initial braces: \[(.*?\)]\[\K(.*?)(?=\])

 

\K is great for excluding all matches prior from the whole match, while still allowing capturing subgroups to be returned as submatches.

Message 129 of 150
(6,382 Views)

XKCD, again.

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 130 of 150
(6,242 Views)