Skip to content

[fix] Regex returned has not the same flags whether "returnString" is true or false #36

Open
@laura-bergoens

Description

@laura-bergoens

Describe the bug

Node.js version: 22.14.0

OS version: Ubuntu 22.04.5 LTS

Description: Flags are different whether the regexp is built with returnString at true or false

Actual behavior

Image

Building a regex with returnString: false will return a Regexp instance with flags gi.
Building a regex with returnString: true will return the regex as a string.

In both cases, the produced regex contains tokens to explicitly expect lower case characters only (in the domain part of the URL I presume). This seems to go against the i flag in the first constructor example.

Expected behavior

  • Either indicate clearly in the doc the difference between regexp produced whether returnString is true or false.
  • Do no add i flag in case of construct with returnString: false

Code to reproduce

  const textWithUrl1 = 'this is my url https://someUrl_HEY.org/';
  const textWithUrl2 = 'this is my url https://someUrl.org/';
  const regexAsRegexp1 = urlRegex({ returnString: false });
  console.log('results with regexAsRegexp (url1): ', textWithUrl1.match(regexAsRegexp1));
  const regexAsString1 = urlRegex({ returnString: true });
  console.log('results with regexAsString (url1): ', textWithUrl1.match(regexAsString1)?.[0] || null);
  const regexAsRegexp2 = urlRegex({ returnString: false });
  console.log('results with regexAsRegexp (url2): ', textWithUrl2.match(regexAsRegexp2));
  const regexAsString2 = urlRegex({ returnString: true });
  console.log('results with regexAsString (url2): ', textWithUrl2.match(regexAsString2)?.[0] || null);

OUTPUT

results with regexAsRegexp (url1):  [ 'https://someUrl_HEY.org/' ]
results with regexAsString (url1):  null
results with regexAsRegexp (url2):  [ 'https://someUrl.org/' ]
results with regexAsString (url2):  rl.org/

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions