【问题标题】:RegEx for occurrence of a constant followed by any string up to a whitespace or end of stringRegEx 用于出现一个常量,后跟任何字符串,直到空格或字符串结尾
【发布时间】:2019-09-04 14:04:17
【问题描述】:

我正在寻找出现“data/”的正则表达式,后跟任何字符串,直到空格或字符串结尾?

2 * data/color * 8 - finds "data/color"
2 * data/coloring * 8 / 34 - finds "data/coloring"
color plus 22 data/credit -- finds "data/credit"

尝试了一些例子;

data/[^\S]+\s
data/[^\S]+(\s|^)
data/\w+\s
data/\w+(\s|^)

感谢您在 LUA (corona SDK) 中找到解决方案的帮助;

data\/[^\t ]+

由于某种原因我必须具体说明不能使用“\s”;

data\/[^\s]+  , fails

【问题讨论】:

  • 你到目前为止的努力? Thanks tried all sorts of combos and can't crack it.你能发布你尝试过的组合吗?
  • 你可以使用data\/[^ ]+try demo
  • [^\S] 否定可能写为\s 的非空白字符您可以使用data/\S+ 而不是demo
  • data/\S+ 在 Corona SDK 中不起作用, data\/[^ ]+ 起作用,但仅适用于空格,因此使用 data\/[^\t ]+ 代替

标签: regex lua coronasdk


【解决方案1】:

在空格之前的任何内容都会如下所示:data\/[^\s]+

data + /(转义的 /)+ [^\s]+(除了空格 1 次或多次)

https://regexr.com/4c8cr

【讨论】:

  • 最初尝试过,由于某种原因在 LUA 中它不起作用,我不得不使用:data\/[^\t]+ 并具体说明空格
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-21
  • 2014-01-04
  • 2021-03-22
  • 2013-09-28
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
相关资源
最近更新 更多