Results 1 to 2 of 2

Thread: Trying to Create REGEXP Pattern That Will Detect Numbers Separated by a Space

  1. #1
    Join Date
    Sep 2022
    Posts
    1

    Trying to Create REGEXP Pattern That Will Detect Numbers Separated by a Space

    Hi all. I'm trying to create a REGEXP pattern that will check if a string contains a set of numbers separated by a space. I have tried the 4 statements below. They all return 0. What am I doing wrong? Thanks.


    Code:
    SELECT '0630 3062' REGEXP '^[0-9]{4} [[:space:]] [0-9]{4}$';
    Code:
    SELECT 'Employee 346 retrad: 0630 3062' REGEXP '[0-9]{4} [[:space:]] [0-9]{4}';
    Code:
    SELECT 'Employee 346 retrad: 0630 3062' REGEXP '[0-9]+ [[:space:]] [0-9]+';
    Code:
    SELECT 'Employee 346 retrad: 0630 3062 1657 in July Assessment' REGEXP '[0-9]+ [[:space:]] [0-9]+';

    The statements are also in this db fiddle

    Thanks.

  2. #2
    Join Date
    Nov 2020
    Posts
    24
    I tested with a VBA function. These all work:
    "[0-9]{4} [0-9]{4}"
    "\d{4} \d{4}"
    "\d{4}\s\d{4}"

    However, they all match on data with groups of 4 or more numbers: "abc 12345 78987"). Using {4,4} made no difference. Could be a deficiency in VBA RegExp which also doesn't like [[:space:]].

    Fiddle queries work by just removing spaces from before and after [[:space:]], however, only the first one is correct if number groups have more than 4 digits. This also works: '^[0-9]{4} [0-9]{4}$'

    None of the versions used in VBA worked in the queries.
    Last edited by June7; 10-01-2022 at 02:50 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •