3

I have an input tag within my python code the looks like this:

<input class="form-control input-lg" type="text" name="name" value="value" placeholder="placeholder" required pattern="^[a-zA-Z0-9.@#$()+! \'_-]+$">

I was able to escape the single quote ' in the required pattern ' but anytime I try to add a double quote ", then it closes the previous double quote (pattern="). I am looking to achieve something like:

pattern="^[a-zA-Z0-9.@#$()+! \'\"_-]+$">

where the \" should allow me to escape the quote but clearly that doesn't work like the \' works. Any help would be greatly appreciated.

Ryan Clark
  • 79
  • 5
  • Possible duplicate of http://stackoverflow.com/questions/4630465/how-to-include-a-quote-in-a-raw-python-string – Learner Dec 03 '15 at 07:13
  • Not a duplicate. My question refers to the need to do this within the attribute of an html element. The answer by eph worked for me. – Ryan Clark Dec 03 '15 at 14:59

3 Answers3

2
pattern="""^[a-zA-Z0-9.@#$()+! \'\"_-]+$"""

You can use """ instead.

vks
  • 67,027
  • 10
  • 91
  • 124
1

You can use \x22 for " and \x27 for '

eph
  • 1,988
  • 12
  • 25
0

You can use r in front of your pattern:

    pattern = r"^[a-zA-Z0-9.@#$()+! \'\"_-]+$"
whoan
  • 8,143
  • 4
  • 39
  • 48
Rohan Amrute
  • 764
  • 1
  • 9
  • 23
  • 1
    That would certainly work with Python. The OP wants however to implement the regex pattern as an attribute of the HTML element input. And there are no possibilities for using raw strings ('r'). – cezar Dec 03 '15 at 09:48
  • Even if it is to be used as an attribute to HTML elememnt input, ('r') can be used. – Rohan Amrute Dec 03 '15 at 10:17