javascript - translating RegEx syntax working in php and python to JS -


i have regex syntax: "(?<=[a-z])-(?=[a-z])"

it captures dash between 2 lowercase letters. in example below second dash captured:

krynica-zdrój, ul. uzdro-jowa

unfortunately can't use <= in js. ultimate goal remove hyphen regex replace.

it seems me need remove hyphen in between lowercase letters.

use

var s = "krynica-zdrój, ul. uzdro-jowa";  var res = s.replace(/([a-z])-(?=[a-z])/g, "$1");  console.log(res);

note first lookbehind turned simple capturing group , second lookahead ok use since - potentially, if there chunks of hyphenated single lowercase letters - able deal overlapping matches.

details:

  • ([a-z]) - group 1 capturing lowercase ascii letter
  • - - hyphen
  • (?=[a-z]) - followed lowercase ascii letter not added result -/g - global modifier, search occurrences of pattern
  • "$1" - replacement pattern containing backreference value stored in group 1 buffer.

vba sample code:

sub removeextrahyphens() dim s string dim reg new regexp  reg.pattern = "([a-z])-(?=[a-z])" reg.global = true  s = "krynica-zdroj, ul. uzdro-jowa" debug.print reg.replace(s, "$1") end sub 

enter image description here


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -