I have a string that is made up of the date and I only want to select a specific area. How to remove in Square.
My sample string is:
Monday, August 4: Shipping
I want string
< / P>
August 4
How to do this in scala
This is a method that uses crude reggae:
val str = "Monday, August 4th: shipping" val regex = " ^ Monday, (\\ d +) [az] {2} ([AG] {3}): [edge] + $ ". R Scale & gt; Collect Option (ARR) {Case Reggae (Day, Month) = & gt; S "$ day $ month"} res130: option [string] = some (4th August)
I used the option
and archive
I used to use regex (day, month) to match the regex out of groups capturing on the pattern, so that if there is no match then I can return none
And then use them to create new strings. To match only the days of weeks / actual months, you may want to improve with that OR or something else in that reggae. Or if you do not really care, you can change "Monday" to match some strings. For instance
val regex = "^ (Monday | Tuesday) (\\ d +) [az] {2} ([as] {3}): [ed] + $" . R Scale & gt; Collect Option (ARR) {Case Reggae (_, Day, Month) = & gt; S "$ day $ month"} res132: option [string] = some (4th August)
No comments:
Post a Comment