skip to Main Content

Can somebody help me to convert php regex to nodejs. My PHP Regex code
preg_match_all('#bhttps?://[^,s()<>]+(?:([wd]+)|([^,[:punct:]s]|/))#', $script, $match);

I’m new to nodejs please help me to convert this.

4

Answers


  1. Here’s the equivalent Node.js regex

    /bhttps?://[^,s()<>]+(?:([wd]+)|([^,p{P}s]|/))/gu
    

    Demo & Explanation: https://regex101.com/r/Y2vlwe/1

    Login or Signup to reply.
  2. const regex = /bhttps?://[^,s()<>]+(?:([wd]+)|([^,[:punct:]s]|/))/g;
    const script = "Your input here";
    
    const matches = script.match(regex);
    console.log(matches);
    
    Login or Signup to reply.
  3. const regex = /bhttps?://[^,s()<>]+(?:([wd]+)|([^,p{P}s]|/))/gu;
    const v = "https://www.google.com";
    const v1 = "sampel text";
    
    const matches = v.match(regex);   // matches
    const matches1 = v1.match(regex); // Not matches
    console.log(matches);
    console.log(matches1);
    Login or Signup to reply.
  4. I assume you’re trying to check for a valid url. easies thing in javascript is to do this:

      let url = 'https://gooogle.com';
    
      try {
       const parts = new URL(url);
       console.log(parts);
    
      } catch(err) {
         console.error('not a valid url', err);
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search