How to escape dollar sign ($) in a string using perl regex

Try this: my %special_characters; $special_characters{“_”} = “\\_”; $special_characters{“\\\$”} = “\\\$”; $special_characters{“{“} = “\\{“; $special_characters{“}”} = “\\}”; $special_characters{“#”} = “\\#”; $special_characters{“%”} = “\\%”; $special_characters{“&”} = “\\&”; Looks weird, right? Your regex needs to look as follows: s/\$/\$/g In the first part of the regex, “$” needs to be escaped, because it’s a special regex character denoting … Read more

How to detect line breaks in a text area input?

You can use match on the string containing the line breaks, and the number of elements in that array should correspond to the number of line breaks. enteredText = textareaVariableName.val(); numberOfLineBreaks = (enteredText.match(/\n/g)||[]).length; characterCount = enteredText.length + numberOfLineBreaks; /\n/g is a regular expression meaning ‘look for the character \n (line break), and do it globally … Read more