简体   繁体   中英

How to get a particular string from text (string) using Groovy/Java?

I am reading a mail "body" from Gmail inbox, I am receiving below text body as string but I need special string(AccountId=13234) out of the whole text body? How can we achieved using Groovy ?

Here is the details below

User: ABC AccountId=13234 CompanyName=xyz

Thanks Team

As mentioned in the comments, there are many ways to do this. Without more info about your specific requirements, it's not possible to know which is best.

A simple solution is:

def result = (s =~ "AccountId=[0-9]+")[0]

This will work if your content is guaranteed to always be AccountId= followed by some number of digits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM