what is the difference between PHP regex and javascript regex

前端 未结 2 633
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 12:40

i am working in regex my regex is /\\[([^]\\s]+).([^]]+)\\]/g this works great in PHP for [http://sdgdssd.com fghdfhdhhd] but when i use this rege

2条回答
  •  感动是毒
    2020-12-10 13:19

    I would like to add this little fact about translating PHP preg_replace Regex in JavaScript .replace Regex :

    
    Result : "-1220025.47"
    

    with PHP, you have to use the quotes "..." around the Regex, a point comma to separate the Regex with the replacement and the brackets are used as a repetition research (witch do not mean the same thing at all.

    
    Result : "-1220025.47"
    

    With JavaScript, no quotes around the Regex, a comma to separate Regex with the replacement and you have to use /g option in order to say multiple research in addition of the /i option (that's why /ig).

    I hope this will be usefull to someone ! Note that the "\," may be suppressed in case of "1,000.00 $" (English ?) kind of number :

    
    
    Result : "-1220025.47"
    

提交回复
热议问题