Code + graphics and text explain the common regular matching __spark of Scala in spark

Source: Internet
Author: User
1. Prepare test Data Set

First create a text file, as we test the data, the contents are as follows: except the third column and the fourth column is empty, the rest is the TAB key between the columns, the first row third column and fourth list 1 spaces, the 2nd row third column and fourth listed 2 spaces, the 3rd row third column and the fourth list 3 spaces, The third and fourth columns of line 4th are 4 spaces:


2.\\s matches any number of whitespace characters

Val rdd7 =sc.textfile ("G:\\zhengze.txt")
Val rdd9 = Rdd7.flatmap (_.split ("\\s"))
println (RDD9)
 rdd9.foreach (x => Print (x+ "*"))
The result is as shown in figure:


3.\\s matches any character that is not blank

Val rdd7 =sc.textfile ("G:\\zhengze.txt")

 val rdd9 = Rdd7.flatmap (_.split ("\\s"))

 println (RDD9)

 Rdd9.foreach (x => Print (x+ "*"))
The results are shown in the following illustration:


4.\\d matches any number of numbers

Val rdd7 =sc.textfile ("G:\\zhengze.txt")

 val rdd9 = Rdd7.flatmap (_.split ("\\d"))

 println (RDD9)

 Rdd9.foreach (x => Print (x+ "*"))
The results are shown in the following illustration:


5.\\d matches any number of non-numeric characters

The result is as shown in the figure:




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.