Regex to match specific functions and their arguments in files

前端 未结 6 1871
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 07:33

I\'m working on a gettext javascript parser and I\'m stuck on the parsing regex.

I need to catch every argument passed to a specific method call _n( and

6条回答
  •  清歌不尽
    2021-01-16 08:06

    We can do this in two steps:

    1)catch all function arguments for _n( or _( method calls

    (?:_\(|_n\()(?:[^()]*\([^()]*\))*[^()]*\)
    

    See demo.

    http://regex101.com/r/oE6jJ1/13

    2)catch the stringy ones only

    "([^"]*)"|(?:\(|,)\s*([^"),]*)(?=,|\))
    

    See demo.

    http://regex101.com/r/oE6jJ1/14

提交回复
热议问题