| 
Welcome, Guest

PERL regex escape char?
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: PERL regex escape char?

PERL regex escape char? 1 year, 11 months ago #135124

  • PCAnalyzer
  • PCAnalyzer
  • OFFLINE
  • Expert Boarder
    Expert Boarder
  • Posts: 115
  • Karma: 3
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

Re:PERL regex escape char? 1 year, 11 months ago #135156

  • krileon
  • krileon
  • ONLINE
  • Moderator
    Moderator
  • Posts: 24022
  • Karma: 695
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
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
If you are a Advanced, Professional, Developer, or CBSubs 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 Advanced, 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 EST to 4:00 PM EST. 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.
--
My personal site(s)/link(s): AllMySocials - Tutorials

Re:PERL regex escape char? 1 year, 11 months ago #135224

  • PCAnalyzer
  • PCAnalyzer
  • OFFLINE
  • Expert Boarder
    Expert Boarder
  • Posts: 115
  • Karma: 3
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

Re:PERL regex escape char? 1 year, 11 months ago #135307

  • krileon
  • krileon
  • ONLINE
  • Moderator
    Moderator
  • Posts: 24022
  • Karma: 695
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.

 
email@..............domain.com
email..............@domain.com
email@--------------domain.com
email______________@domain.com
 


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

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


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

 
email..............@domain.com
email@--------------domain.com
email______________@domain.com
 


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

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


Post edited by: krileon, at: 2010/06/10 23:27
Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
If you are a Advanced, Professional, Developer, or CBSubs 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 Advanced, 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 EST to 4:00 PM EST. 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.
--
My personal site(s)/link(s): AllMySocials - Tutorials

Re:PERL regex escape char? 1 year, 11 months ago #135393

  • PCAnalyzer
  • PCAnalyzer
  • OFFLINE
  • Expert Boarder
    Expert Boarder
  • Posts: 115
  • Karma: 3
Thank you, anyway the problem is the same: the escape char "backslash" is removed when you save the field, why?

Re:PERL regex escape char? 1 year, 11 months ago #135437

  • krileon
  • krileon
  • ONLINE
  • Moderator
    Moderator
  • Posts: 24022
  • Karma: 695
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.

 
/^(?:[a-zA-Z0-9]+[-]?[.]?[_]?[+]?[%]?)+@(?:«»(?:[a-zA-Z0-9]+[-]?)+[.])+[a-zA-Z]{2,6}$/
 
Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
If you are a Advanced, Professional, Developer, or CBSubs 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 Advanced, 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 EST to 4:00 PM EST. 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.
--
My personal site(s)/link(s): AllMySocials - Tutorials
  • Page:
  • 1
Time to create page: 1.33 seconds