Regux

目標文字:

when
sampleEntity : SampleEntity($code1:code)
sampleEntity2 : SampleEntity2()
if ($code1 == "1" && #max(1, 0) == 1 && #trim("apple ").equals("apple")) do[_1]
else if ($code1 == "2") do[_2]
then

需透過Regular pattern, 取得井字號後面的function name以及input args

原始Pattern #(\w+)\((.+)\)

  • function name正確取得max
  • 但args卻取了整串到: 1, 0) == 1 && #trim("apple ").equals("apple")
  • 看起來是中間的 . 範圍太大, 導致到最後一個 \)之前都剛成args了

改。Pattern #(\w+)\(([^\)]+)\)

  • 加入了不等於 ^ 的判斷
  • function name正確取得maxstr
  • args也正確抓到了1, 0以及apple
  • 但多了使用限制:input args中不能有close字元
  • #trim(" ) ")就無法接受
    正在思考更好的解決方案…

Leave a comment