在字符串java正则表达式中查找字段
我不擅长Java正则表达式 我有以下文字在字符串java正则表达式中查找字段,java,regex,pattern-matching,expression,Java,Regex,Pattern Matching,Expression,我不擅长Java正则表达式 我有以下文字 [[image:testimage.png||height=\"481\" width=\"816\"]] 我想从上面的文本中提取图像:、高度和宽度。有人能帮我写正则表达式来实现它吗?如果这是您的精确字符串 [[image:testimage.png||height=\"481\" width=\"816\"]] 然后尝试以下方法(原始): 这是一种方法,另一种(更好)方法是使用一个,如果这是您的确切字符串 [[image:testimage.png
[[image:testimage.png||height=\"481\" width=\"816\"]]
我想从上面的文本中提取图像:、高度和宽度。有人能帮我写正则表达式来实现它吗?如果这是您的精确字符串
[[image:testimage.png||height=\"481\" width=\"816\"]]
然后尝试以下方法(原始):
这是一种方法,另一种(更好)方法是使用一个,如果这是您的确切字符串
[[image:testimage.png||height=\"481\" width=\"816\"]]
然后尝试以下方法(原始):
这是一种方法,另一种(更好)方法是使用一个这个正则表达式将匹配一个属性及其关联的值。您必须遍历它在源字符串中找到的每个匹配项,才能获得所需的所有信息
(\w+)[:=]("?)([\w.]+)\2
您有三个捕获组。其中两个是您感兴趣的:
- 组1:属性的名称。(图像、高度、宽度…)
- 第3组:属性的值
(\w+) #Group 1: Match the property name.
[:=] #The property name/value separator.
("?) #Group 2: The string delimiter.
([\w.]+) #Group 3: The property value. (Accepts letters, numbers, underscores and periods)
\2 #The closing string delimiter if there was one.
此正则表达式将匹配属性及其关联值。您必须遍历它在源字符串中找到的每个匹配项,才能获得所需的所有信息
(\w+)[:=]("?)([\w.]+)\2
您有三个捕获组。其中两个是您感兴趣的:
- 组1:属性的名称。(图像、高度、宽度…)
- 第3组:属性的值
(\w+) #Group 1: Match the property name.
[:=] #The property name/value separator.
("?) #Group 2: The string delimiter.
([\w.]+) #Group 3: The property value. (Accepts letters, numbers, underscores and periods)
\2 #The closing string delimiter if there was one.
试试这个正则表达式:
((?:image|height|width)\D+?([a-zA-Z\d\.\\"]+))
你将得到两组
e、 g
((?:image|height|width)\D+?([a-zA-Z\d\.\\"]+))
你将得到两组
e、 g
一个很好的尝试和错误的工具:另一个很好的工具是你在问题的结尾缺少一些东西。。。“我有n”?一个很好的尝试和错误的工具:另一个很好的工具是你在问题的末尾缺少了一些东西。。。“我没有”??