Regex Whitespace 4. How to match whitespace and non whitespace characters.

Everything you need to know about Regex. (5 Part Series)

1 1.Introduction about Regex
2 2. The dot(.)
3 3.Matching digits and non digits character.
4 4. How to match whitespace and non whitespace characters.
5 5.How to match word and non word characters.

The \s expression any whitespace characters[space,tab] and \S
expression matches every non whitespace characters.
e.g :- String Pattern :- \\S\\s\\S\\s\\S
Test String :- a b c def

Note:- Use \\ instead of \ in Java.

Sample code in Java:

import java.io.;
import java.util.Scanner;
import java.util.regex.
;
class RegexSearch{
public void tester(String Regex_Pattern){
Scanner sc= new Scanner(System.in);
String Test_String = sc.nextLine();
Pattern p = Pattern.compile(Regex_Pattern);
Matcher m = p.matcher(Test_String);
while(m.find()){
System.out.print(m.group());
}
}
}
public class Main{
public static void main(String[]args){
RegexSearch obj = new RegexSearch();
obj.tester(“\\S\\s\\S\\s\\S”);
}
}

You can view the code here also.

Do read my previous blog on Regex.

图片[1]-Regex Whitespace 4. How to match whitespace and non whitespace characters. - 拾光赋-拾光赋

1.Introduction about Regex

Ayush Shalya ・ Mar 29 ’20 ・ 1 min read

#regex #java
图片[1]-Regex Whitespace 4. How to match whitespace and non whitespace characters. - 拾光赋-拾光赋

2. The dot(.)

Ayush Shalya ・ Mar 29 ’20 ・ 1 min read

#regex #java
图片[1]-Regex Whitespace 4. How to match whitespace and non whitespace characters. - 拾光赋-拾光赋

3.Matching digits and non digits character.

Ayush Shalya ・ Mar 30 ’20 ・ 1 min read

#regex #java

                   Have a nice day, Coders.

Enter fullscreen mode Exit fullscreen mode

Everything you need to know about Regex. (5 Part Series)

1 1.Introduction about Regex
2 2. The dot(.)
3 3.Matching digits and non digits character.
4 4. How to match whitespace and non whitespace characters.
5 5.How to match word and non word characters.

原文链接:Regex Whitespace 4. How to match whitespace and non whitespace characters.

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容