在众多正则表达式的教程中,对于 \s 的解释都是 匹配空格 。但在对于java中的多种空格, \s 不能对他们全部进行匹配

  • 半角空格:“ ”.
    • Unicode编码为:\u0020
    • 可以 通过正则表达式中的 \s 进行匹配
  • 全角空格:“ ”
    • Unicode编码为:\u3000
    • 不能 通过正则表达式中的 \s 进行匹配
  • 不换行空格(连续空格)
    • Unicode编码为:\u00A0,主要用在office中。
    • 不能 通过正则表达式中的 \s 进行匹配

文末附上测试所用代码。

匹配三种空格,我的简陋解决方案

\s 匹配空格的位置,改用 [\u3000|\u0020|\u00A0] 。其中, [] :代表一个字符组 匹配包含括号内元素的字符

实验代码如下:

public static void testSpace(){
        String regexOriginal = "空格\\s+匹配";
        String regexUpdate = "空格[\\u0020|\\u3000|\\u00A0]+匹配";
        String str0020 = "空格\u0020匹配";
        String str3000 = "空格\u3000匹配";
        String str00A0 = "空格\u00A0匹配";
        Boolean b0020 = false;
        Boolean b3000 = false;
        Boolean b00A0 = false;
        Pattern pattern = Pattern.compile(regexOriginal);
        Matcher matcher0020 = pattern.matcher(str0020);
        Matcher matcher3000 = pattern.matcher(str3000);
        Matcher matcher00A0 = pattern.matcher(str00A0);
        b0020 = matcher0020.find();
        b3000 = matcher3000.find();
        b00A0 = matcher00A0.find();
        System.out.println("\\s可以匹配到\\u0020吗?(半角)" + b0020.toString());
        System.out.println("\\s可以匹配到\\u3000吗?(全角)" + b3000.toString());
        System.out.println("\\s可以匹配到\\u00A0吗?(连续空格)" + b00A0.toString());
                    \s能否匹配三种空格在众多正则表达式的教程中,对于\s的解释都是匹配空格。但在java中,这种说法我认为是不正确的,因为对于在java中的多种空格,\s不能对他们全部进行匹配。半角空格:“ ”.Unicode编码为:\u0020可以通过正则表达式中的\s进行匹配全角空格:“ ”Unicode编码为:\u3000不能通过正则表达式中的\s进行匹配不换行空格(连续空格)...
你前面学习了使用\s搜索空格(小写的s)。你也可以搜索除空白或空格之外的所有内容。
使用\S搜索非空格,这是一个大写的s。此模式将不匹配空格、回车符、制表符、换页和新行字符。你可以想象它类似于字符类[^ \r\t\f\n\v]。
var whiteSpace = "Whitespace. Whitespace everywhere!"
var nonSpaceRegex = /\S/...
				
学习笔记: java正则,我们习惯用 “\s” 去匹配空格,但是存在一些特殊的空格没法匹配,可以使用 [\u3000|\u0020|\u00A0] 来代替 \s \u0020 : 半角空格“ ”,\s可以匹配到 \u3000 : 全角空格“ ”,\s无法匹配 \u00A0 : 多用于office,\s无法匹配 转载自:https://www.cnblogs.com/XM-CHC/p/12366979.html
Java正则表达式是由java.util.regex的Pattern和Matcher类实现的。Pattern对象表示经编译的正则表达式,可以使用静态的compile()方法将表示正则表达式的字符串编译成Pattern对象。Matcher对象则用于对字符串进行匹配操作。 在Java正则表达式可以应用于不同的功能,比如判断功能和分割功能。 判断功能可以通过使用matches()方法来判断一个字符串是否符合指定的正则表达式。例如,可以使用matches()方法判断输入的手机号是否以13或18开头。 分割功能可以通过使用正则表达式的split()方法来实现。该方法可以将一个字符串按照指定的正则表达式进行分割,返回一个字符串数组。这在处理文本数据时非常有用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [java正则表达式](https://blog.csdn.net/m0_62618110/article/details/123704869)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
vue 报错 You are using the runtime-only build of Vue where the template compiler is not available.
vue 报错 You are using the runtime-only build of Vue where the template compiler is not available. wavyhair_: vue 报错 You are using the runtime-only build of Vue where the template compiler is not available. 不知道为什么被封号了: 使用方案2解决了,谢谢!