[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

cl-ppcre: "^([A-Z]) (.*);|^\\([a-z_]*)|^([a-z]);" gives error

Frank GOENNINGER

5/7/2016 9:39:00 AM

Hi again,

.... working my way through perl regexes.

I have (using cl-ppcre):

(multiple-value-bind (match regs)
(scan-to-strings "^([A-Z]) (.*);|^\\([a-z_]*)|^([a-z]);"
"\\dump_state"))


This piece of code gives the following error:

Expected end of string. at position 25 in string "^([A-Z]) (.*);|^\\([a-z_]*)|^([a-z]);"
[Condition of type PPCRE-SYNTAX-ERROR]

When I remove the second pair of () the error vanishes...

When I use Eddi's Regex Coach (thanks, Eddi!) I don't get an error -
but a wonderfully parsed split string list.

I want to be able to match the following cases:

"F 1234;" -> A single uppercase char, followed by a space, followed by a
"value", followed by a semicolon;

"f;" -> A single lowercase, followed by a semicolon;

"\dump_state" -> A backslash, followed by a sequence of lowecase chars
which may also be an underscore.

Any help or hint much appreciated!

Thx!

;;; Frank

2 Answers

William James

5/7/2016 2:24:00 PM

0

Frank DG1SBG wrote:

> (scan-to-strings "^([A-Z]) (.*);|^\\([a-z_]*)|^([a-z]);"
^^
||
||

Backslashes in a string that is a regular expression are tricky.

The effect of these two backslashes is not to insert a backslash
into the regexp, but to escape the following parenthesis, transforming
it from a metacharacter to an ordinary character.

Four backslashes are needed here.

--
If confirmed, Garland would be the fourth Jewish justice on the nation's
highest court, which is comprised entirely of Jews and Catholics. The three
current Jewish members of the Supreme Court are Ruth Bader Ginsburg, Elana
Kagan, and Stephen Breyer.
www.jta.org/2016/03/16/news-opinion/united-states/obama-to-name-jewish-federal-judge-to-supreme-court

Madhu

5/7/2016 3:25:00 PM

0


* Frank DG1SBG <m2bn4idx6n.fsf@googlemail.com> :
Wrote on Sat, 07 May 2016 11:39:12 +0200:

| (scan-to-strings "^([A-Z]) (.*);|^\\([a-z_]*)|^([a-z]);"
| "\\dump_state")
|
| This piece of code gives the following error:
|
| Expected end of string. at position 25 in string "^([A-Z]) (.*);|^\\([a-z_]*)|^([a-z]);"
| [Condition of type PPCRE-SYNTAX-ERROR]

If this error message isn't obvious, you should try:

* (format t "^([A-Z]) (.*);|^\\([a-z_]*)|^([a-z]);")

This prints

^([A-Z]) (.*);|^\([a-z_]*)|^([a-z]);
^^^^^^^
does this look right? as a perl regexp it doesn't! Remember \ is an
escape character for lisp strings

| When I remove the second pair of () the error vanishes...

this is probably better solved with an extra level of backslash
quoting. try \\\
--- Madhu