Regular Expression to Match a Dot

Regular Expression to match dot separated list with no dot on the end and allow asterisk at the end

You may use

^(?!.*[.*]{2})[a-z0-9*_:-]+(?:\.[a-z0-9*_:-]+)+$

See the regex demo (at regexstorm, line endings are CRLF and \r? is used for the multiline string demo purpose only).

Details

  • ^ - start of string
  • (?!.*[.*]{2}) - no two consecutive . and * are allowed
  • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -
  • (?:\.[a-z0-9*_:-]+)+ - 1 or more consecutive occurrences of

    • \. - a dot
    • [a-z0-9*_:-]+ - 1 or more ASCII lowercase letters, digits, *, _, : or -
  • $ - end of string.

python regex: match the dot only, not the letter before it

Your pattern can be reduced to and fixed as

(?<=(?<![.\s])[a-zA-Z])\.

See the regex demo.

If you need to also match multiple dots, put back + after the \..

Details:

  • (?<=(?<![.\s])[a-zA-Z]) - a positive lookbehind that matches a location that is immediately preceded with
    • (?<![.\s]) - a negative lookbehind that fails the match if there is a . or whitespace immediately to the left of the current location
    • [a-zA-Z] - an ASCII letter
  • \. - a literal dot.

Look, your pattern is basically an alternation of two patterns, (?<!\.|\s)[a-z]\. and (?<!\.|\s)[A-Z]\., the only difference between which is [a-z] and [A-Z]. It is clear the same alternation can be shortened to (?<!\.|\s)[a-zA-Z]\. The [a-zA-Z] must be put into a non-consuming pattern so that the letters could not be eaten up when splitting, so using a positive lookbehind is a natural solution.

Regex to match a word or a dot between words (optionally) in a string

You can use

/(?:\w+\()+|\b(\w+(?:\.\w+)?)\b(?!')/g

If your JavaScript environment supports ECMAScript 2018+, you may use

/(?:\w+\()+|(?<!')\b(\w+(?:\.\w+)?)\b(?!')/g

See the regex demo #1 and regex demo #2. Details:

  • (?:\w+\()+ - match one or more sequences of one or more word chars and then ( char
  • | - or
  • \b - match a word boundary
  • (?<!') - ' is not allowed to be immediately to the left of the current location
  • (\w+(?:\.\w+)?) - Group 1: one or more word chars and then an optional occurrence of a . and then one or more word chars
  • \b - a word boundary
  • (?!') - not followed with ' char.

See the JavaScript demo:

const text = ",DECODE(T3.ATEST,' ',T3.BATEST\n ,DECODE(NVL(T4.BATEST,'9')\n ,'1',NVL(T4.BATEST,' ')  ,T3.BATEST)) ,DECODE(ATEST,' ',BATEST ,DECODE(NVL(BATEST,'9')   ,'1',NVL(BATEST,' ')    ,BATEST))";
const regex = /(?:\w+\()+|\b(\w+(?:\.\w+)?)\b(?!')/g;
let results=[],m;
while(m = regex.exec(text)) {
if (m[1] !== undefined) {
results.push(m[1]);
}
}
console.log(results);

Regex match every dot

What you might do to match every dot or comma and assuming that the attribute value is between single or double quotes is to match what you don't want and to capture in a group what you want to keep.

If you don't want to match a dot in the href you could match it with href=" followed by [^"]*" or '[^']*'. Then you could use an alternation | to capture in a group a dot or a comma using ([.,])

href=(?:"[^"]*"|'[^']*')|([.,])

regular expression to match one or two dots

. matches any character so needs escaping i.e. \., or \\. within a Java string (because \ itself has special meaning within Java strings.)

You can then use \.\. or \.{2} to match exactly 2 dots.

Regular expression to match dot which has letter after it, before next dot or end of line

This regex possibly with some small changes should work. ^(?:\.[^\.\s]*[a-zA-Z][^\.\s]*)+$

Regex101 demo.

Breakdown of how it works:

  • ^ - Start of new line
  • (?:\.[^\.\s]*[a-zA-Z][^\.\s]*) - Grab period followed by all text before the next period or new line. Ensure there is at least one letter.

    • \. - Start with period.
    • [^\.\s]* - Anything but a space or . any number of times.
    • [a-zA-Z] - Ensure at least one letter per period.
    • [^\.\s]* - Anything but a space or . any number of times.
  • + - Once or more
  • $ - End of line

Dot in regular expression (regex)

Try [.]

Dot isn't special inside character class.

regex to match dot and number follow the dot

You could try

let pat = /\.[0-9]/
if(pat.test(number))
{
//do something
}


Related Topics



Leave a reply



Submit