dokuwiki-plugin-bureaucracy icon indicating copy to clipboard operation
dokuwiki-plugin-bureaucracy copied to clipboard

Whitespaces in regexp

Open elaratain opened this issue 10 years ago • 4 comments

Regular expressions containing whitespaces in the literal form, e.g. ( )+ are not checked. It is necessary to use \s instead (not a severe problem, but maybe it should be documented somewhere - took me quite some time)

elaratain avatar Jul 01 '15 10:07 elaratain

I have no idea what you mean. Please, could you give an example of syntax which triggers this issue, or pointer to the code you are referring?

Klap-in avatar Jul 01 '15 11:07 Klap-in

I have a form with a textfield and a regular expression to check against. If the regular expression contains ( ) like this: textbox "IBAN" /^[A-Z]{2}( )?\d{4}?$/ it does not check the value, I have to write it like this: textbox "IBAN" /^[A-Z]{2}\s?\d{4}?$/ Standard regexp allows both expressions

elaratain avatar Jul 01 '15 12:07 elaratain

@elaratain I believe your first example is incorrect preg RegEx, which is what Bureaucracy seems to use (I've only skim read the code).

First example should be:- textbox "IBAN" /^[A-Z]{2}((\s)?\d{4})?$/ ...unless you plan on allowing more than one space before the optional 4 digits (after the required two upper-case letters). Note that PHP supports both preg (PCRE) and ereg - it could be that Bureaucracy actually uses ereg to validate optional field parameters.

Your second example doesn't seem like it should work - I suspect I've wrongly guessed what you're trying to validate

SFITCS avatar Oct 31 '16 06:10 SFITCS

I'm reopening this issue because I also have a problem with spaces in regex. Here's my code: textbox "Tags" /^[A-Za-z ]+$/ There is a space character between the 'z' and the ']' Objective : accept only space separated words Behavior : accepts everything Just to make sure I've tested the regex on https://regex101.com/ and it works fine.... Any idea anyone ?

BTW I've tried backslashing the space (same behavior), also if I replace the space with let's say a comma the regex works as it should. And I not want to use \s because that also allows tabs

erikrob avatar Nov 24 '20 15:11 erikrob