Ask Your Question
2

Why does this regular expression work in Regex Tester but not in LibreOffice Find and Replace? [closed]

asked 2014-06-24 22:11:54 +0200

Fogest gravatar image

updated 2014-06-24 23:36:20 +0200

bencomp gravatar image

I am using the following regular expression:

 .*@cs\s

On Regexpal my regex does what it is suppose to, however on LibreOffice is doesn't.

The Regex above should match the following sample cases:

anytext@cs
orthistexttoo@cs

It however should not match cases where the is text following the "cs" part. The Regex I created above according to RegexPal works, however in LibreOffice nothing is found. Here is an example of a case that should not be matched:

butNotThisText@cs.IhavestuffAfterTheCS.

Am I doing something wrong here?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-02-26 09:55:27.602927

1 Answer

Sort by » oldest newest most voted
2

answered 2014-06-24 23:17:25 +0200

David gravatar image

updated 2014-06-24 23:25:08 +0200

The LibreOffice/OpenOffice "flavour" of regex doesn't know your \s, as you have discovered. According to Regular-Expressions.info:

\s stands for "whitespace character". Again, which characters this actually includes, depends on the regex flavor. In all flavors discussed in this tutorial, it includes [ \t\r\n\f]. That is: \s matches a space, a tab, a line break, or a form feed.

If that is indeed what you want, you'll need to use this for your LibO Calc (or Writer) regex:

.*@cs([:space:]|$|\t|\r)

At least in my little test it seemed to behave the way you want. Further on LibO/OO regex:

screenshot

edit flag offensive delete link more

Comments

I am just going for an effect where it only selects entries matching the beginning case and NOTHING after the "cs" part. Some rows I have include something like cs.extra.com or something along this things which I do not want to return as matches. They must specifically end with a "cs"

Fogest gravatar imageFogest ( 2014-06-25 01:39:47 +0200 )edit

So ... did the solution I suggested work for you? or no? You could also try .*@cs(?!.), using a negative lookahead which appears to be supported, but it will not find "text@cs", i.e., "cs" followed by a space.

David gravatar imageDavid ( 2014-06-25 09:32:27 +0200 )edit

Question Tools

2 followers

Stats

Asked: 2014-06-24 22:11:54 +0200

Seen: 784 times

Last updated: Jun 24 '14