Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在字符串java正则表达式中查找字段_Java_Regex_Pattern Matching_Expression - Fatal编程技术网

在字符串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

我不擅长Java正则表达式

我有以下文字

[[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

  • 高度=\“481\”
  • 481
  • 试试这个正则表达式:

    ((?:image|height|width)\D+?([a-zA-Z\d\.\\"]+))
    
    你将得到两组

    e、 g

  • 高度=\“481\”
  • 481

  • 一个很好的尝试和错误的工具:另一个很好的工具是你在问题的结尾缺少一些东西。。。“我有n”?一个很好的尝试和错误的工具:另一个很好的工具是你在问题的末尾缺少了一些东西。。。“我没有”??