Basic Special Characters and Symbols Within Regular Expressions : sub with regular expressions « String « Ruby






Basic Special Characters and Symbols Within Regular Expressions


Character      Meaning 
^              Anchor for the beginning of a line
$              Anchor for the end of a line
\A             Anchor for the start of a string
\Z             Anchor for the end of a string
.              Any character
\w             Any letter, digit, or underscore
\W             Anything that \w doesn't match
\d             Any digit
\D             Anything that \D doesn't match (non-digits)
\s             Whitespace (spaces, tabs, newlines, and so on)
\S             Non-whitespace (any visible character)

 








Related examples in the same category

1.Regular Expression Character and Sub-Expression Modifiers
2.To replace the first two characters of a string with 'Hello':
3.To change the last two letters
4.scan is the iterator method you require:
5.scan(/../): . means Any character
6.scan (/\w\w/): \w means Any letter, digit, or underscore
7.Index string by regular expression