Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. How can i change regex to work in javascript

How can i change regex to work in javascript

Scheduled Pinned Locked Moved JavaScript
regexquestioncsharpjavascriptasp-net
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AditSheth
    wrote on last edited by
    #1

    Hello I have regex expression that is work in asp.net for finding link

    SET objRegex = NEW regexp
    objRegex.Pattern = "(\b(?:(?:https?|ftp|file)://|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$]))"

    Now i want to use this expression in javascript. how can i write ? I tried with this but not working.

    var re = new RegExp(/\b(/?:(/?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])/g);

    Is there any Converter available for this?

    “Before you start some work, always ask yourself three questions - Why am I doing it, What the results might be and Will I be successful. Only when you think deeply and find satisfactory answers to these questions, go ahead.” -Chanakya Thanks Adit

    M 1 Reply Last reply
    0
    • A AditSheth

      Hello I have regex expression that is work in asp.net for finding link

      SET objRegex = NEW regexp
      objRegex.Pattern = "(\b(?:(?:https?|ftp|file)://|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$]))"

      Now i want to use this expression in javascript. how can i write ? I tried with this but not working.

      var re = new RegExp(/\b(/?:(/?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])/g);

      Is there any Converter available for this?

      “Before you start some work, always ask yourself three questions - Why am I doing it, What the results might be and Will I be successful. Only when you think deeply and find satisfactory answers to these questions, go ahead.” -Chanakya Thanks Adit

      M Offline
      M Offline
      Matt Meyer
      wrote on last edited by
      #2

      The forward slashes are causing your problems because they're telling the interpreter that it's the end of the expression since they're not escaped. Converting your expression from the original into the javascript should only require a copy/paste and manually escaping the pattern's forward slashes. Ie, (?:https?|ftp|file)://|www\.|ftp\.) becomes (?:https?|ftp|file):\/\/|www\.|ftp\.) Here's a Regex reference for javascript that can help you convert your expression: http://www.w3schools.com/jsref/jsref_obj_regexp.asp[^] Also, there's a regular expression forum on here: http://www.codeproject.com/Forums/1580841/Regular-Expressions.aspx[^] They will probably give you more help about regex syntax problems than the javascript forum.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups