Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Regular expressions in Scala and sample Analysis of pattern matching

2025-04-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces regular expressions in Scala and sample analysis of pattern matching. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!

regular expression

//"" Native expression val regex="""([0-9]+)([a-z]+)"".r val numPattern="[0-9]+".r val numberPattern=""\s+[0-9]+\s+"".r

Description: .r() Method Introduction: Scala converts strings to regular expressions

/** You can follow a string with `.r`, turning it into a `Regex`. E.g. * * `"""A\w*""".r` is the regular expression for identifiers starting with `A`. */ def r: Regex = r()

Pattern match one.

//findAllIn() method returns iterator over all matches for(matchString s"$x$y" * }).toList // List(hath, hatth, hattth, hatttt) * }}} * * Attempting to retrieve match information before performing the first match * or after exhausting the iterator results in [[java.lang.IllegalStateException]]. * See [[scala.util.matching.Regex.MatchIterator]] for details. * * @param source The text to match against. * @return A [[scala.util.matching.Regex.MatchIterator]] of matched substrings. * @example {{{for (words println(num+"\t"+blog) case _=>println("hahaha... ") }

val line="93459h spark" line match{ case numitemPattern(num,blog)=> println(num+"\t"+blog) case _=>println("hahaha... ") }

All program source code in this section

package kmust.hjr.learningScala19/** * Created by Administrator on 2015/10/17. */object RegularExpressOps { def main(args:Array[String]):Unit={ val regex=""([0-9]+)([a-z]+)"".r//"" Native expression val numPattern="[0-9]+".r val numberPattern=""\s+[0-9]+\s+"".r //findAllIn() method returns iterator for(matchString println(num+"\t"+blog) case _=>println("hahaha... ") } }}

The above is all the content of this article "Regular expressions in Scala and sample analysis of pattern matching", thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report