PERL regex escape char?

10 years 3 weeks ago #135124 by PCAnalyzer
PERL regex escape char? was created by PCAnalyzer
If i use the escape char '_backslash_', it automatically strip it out when i save the field, why?

Post edited by: PCAnalyzer, at: 2010/06/09 23:09

Please Log in to join the conversation.

10 years 3 weeks ago #135156 by krileon
Replied by krileon on topic Re:PERL regex escape char?
PCAnalyzer wrote:

If i use the escape char "\", it automatically removes it when i save the field, why?

You're using regex as if it's "Forbidden words..". This is not how regex works, please review the information found here on regex usage.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

10 years 3 weeks ago #135224 by PCAnalyzer
Replied by PCAnalyzer on topic Re:PERL regex escape char?
I'm using this regular expression to match user's e-mail:
/^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+_backslash_.[a-zA-Z]{2,6}$/

Is it wrong?

Update:
Backslash is stripped here also, so i used _backslash_ here.

Post edited by: PCAnalyzer, at: 2010/06/09 23:13

Please Log in to join the conversation.

10 years 3 weeks ago #135307 by krileon
Replied by krileon on topic Re:PERL regex escape char?
Your email regex appears correct, but it's highly dependent on what content the user is providing. For example the following emails will validate, but is clearly not valid with the regex you've provided.

[code:1]
email@..............domain.com
email..............@domain.com
email@
domain.com
email______________@domain.com
[/code:1]

You could use the following for example to remove consecutive periods in the domain.

[code:1]
/^[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}$/
[/code:1]

However the following would still validate. It's simply a matter of trial and error until you've something satisfactory.

[code:1]
email..............@domain.com
email@
domain.com
email______________@domain.com
[/code:1]

You could then add more checks to prevent consecutive periods AND dashes (dashes optional) using the following.

[code:1]
/^(?:[a-zA-Z0-9]+-?\.?_?\+?%?)+@(?:«»(?:[a-zA-Z0-9]+-?)+\.)+[a-zA-Z]{2,6}$/
[/code:1]

Post edited by: krileon, at: 2010/06/10 23:27


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

10 years 3 weeks ago #135393 by PCAnalyzer
Replied by PCAnalyzer on topic Re:PERL regex escape char?
Thank you, anyway the problem is the same: the escape char "backslash" is removed when you save the field, why?

Please Log in to join the conversation.

10 years 3 weeks ago #135437 by krileon
Replied by krileon on topic Re:PERL regex escape char?
PCAnalyzer wrote:

Thank you, anyway the problem is the same: the escape char "backslash" is removed when you save the field, why?

I don't know, if that's the case then simply encase in brackets as follows.

[code:1]
/^(?:[a-zA-Z0-9]+[-]?[.]?[_]?[+]?[%]?)+@(?:«»(?:[a-zA-Z0-9]+[-]?)+[.])+[a-zA-Z]{2,6}$/
[/code:1]


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.449 seconds

Facebook Twitter LinkedIn