I seem to be unable to create text nodes in html which show the accented characters: if i pass them directly, i get "white question mark in black rhombus"; if i replace the accented characters by the corresponding html
entities, i get the entities printed verbatim.
Produces the following text:
How do I have to convert the string to get accented characters in HTML?
22.7k7 gold badges70 silver badges87 bronze badges
asked Feb 22, 2015 at 13:16
You are probably missing a page encoding. Make sure your HTML includes either this:
Or this (HTML5):
answered Feb 22, 2015 at 13:20
15.1k7 gold badges56 silver badges89 bronze badges
It turned out my xemacs encodes with ISO-8859-1; the current version can not be easily set to UTF-8.
The solution was to change the encoding info from "utf-8" to "iso-8859-1" in the xhtml's header:
Now i can set a string to 'àò' in my js file, and the browser will display it correctly.
answered Feb 23, 2015 at 19:21
1,0473 gold badges10 silver badges22 bronze badges
You construct a regular expression in one of two ways:
You construct a regular expression in one of two ways:
Writing a regular expression pattern
A regular expression pattern is composed of simple characters, such as
Note: If you are already familiar with the forms of a regular expression, you may also read the cheatsheet for a quick lookup for a specific pattern/construct.
Using simple patterns
Simple patterns are constructed of characters for which you want to find a direct match. For example, the pattern
Using special characters
When the search for a match requires something more than a direct match, such as finding one or more b's, or finding white space, you can include special
characters in the pattern. For example, to match a single
The following pages provide lists of the different special characters that fit into each category, along with descriptions and examples.Assertions
Assertions include boundaries, which indicate the beginnings and endings of lines and words, and other patterns indicating in some way that a match is possible (including look-ahead, look-behind, and conditional expressions).Character classes
Distinguish different types of characters. For example, distinguishing between letters and digits.
Groups group multiple patterns as a whole, and capturing groups provide extra submatch information when using a regular expression pattern to match against a string. Backreferences refer to a previously captured group in the same regular expression.Quantifiers
Indicate numbers of characters or expressions to match.Unicode property escapes
Distinguish based on unicode character properties, for example, upper- and lower-case letters, math symbols, and punctuation.
If you want to look at all the special characters that can be used in regular expressions in a single table, see the following:
If you need to use any of the special characters literally (actually searching for a
Similarly, if you're writing a regular expression literal and need to match a slash ("/"), you need to escape that (otherwise, it terminates the pattern). For instance, to search for the string "/example/" followed by one or more alphabetic characters, you'd use
To match a literal backslash, you need to escape the backslash. For instance, to match the string
"C:\" where "C" can be any letter, you'd use
If using the
If escape strings are not already part of your pattern you can add them using
The "g" after the regular expression is an option or flag that performs a global search, looking in the whole string and returning all matches. It is explained in detail below in Advanced Searching With Flags.
Parentheses around any part of the regular expression pattern causes that part of the matched substring to be remembered. Once remembered, the substring can be recalled for other use. See Groups and backreferences for more details.
Regular expressions are used with the
When you want to know whether a pattern is found in a string, use the
In the following example, the script uses the
If you do not need to access the properties of the regular expression, an alternative way of creating
(See Using the global search flag with
If you want to construct the regular expression from a string, yet another alternative is this script:
With these scripts, the match succeeds and returns the array and updates the properties shown in the following table.
As shown in the second form of this example, you can use a regular expression created with an object initializer without assigning it to a variable. If you do, however, every occurrence is a new regular expression. For this reason, if you use this form without assigning it to a variable, you cannot subsequently access the properties of that regular expression. For example, assume you have this script:
However, if you have this script:
The occurrences of
Advanced searching with flags
Regular expressions have optional flags that allow for functionality like global searching and case-insensitive searching. These flags can be used separately or together in any order, and are included as part of the regular expression.
To include a flag with the regular expression, use this syntax:
Note that the flags are an integral part of a regular expression. They cannot be added or removed later.
You could replace the line:
and get the same result.
Using the global search flag with exec()
Using unicode regular expressions
The "u" flag is used to create "unicode" regular expressions; that is, regular expressions which support matching against unicode text. This is mainly accomplished through the use of Unicode property escapes, which are supported only within "unicode" regular expressions.
For example, the following regular expression might be used to match against an arbitrary unicode "word":
There are a number of other differences between unicode and non-unicode regular expressions that one should be aware of:
Unicode regular expressions have different execution behavior as well.
Note: Several examples are also available in:
Using special characters to verify input
In the following example, the user is expected to enter a phone number. When the user presses the "Check" button, the script checks the validity of the number. If the number is valid (matches the character sequence specified by the regular expression), the script shows a message thanking the user and confirming the number. If the number is invalid, the script informs the user that the phone number is not valid.
The regular expression looks for:
An online tool to learn, build, & test Regular Expressions.Regex tester
An online regex builder/debuggerRegex interactive tutorial
An online interactive tutorials, Cheatsheet, & Playground.Regex visualizer
An online visual regex tester.