Ram
Ram

Reputation: 1

Regular expression to search for specific line in a paragraph

I am trying to search for a specific line in a paragraph. Could somebody help me out with a regular expression.

I need to search for " unable to extend table" inside the paragraph :

BasicData:RootContextID=3a88bfa0c11511e1915e9e572a3f5ee0,AuditTimestamp=1340883271834,ContextID=3a88bfa0c11511e1915e9e572a3f5ee0,AuditSchemaName=wMSession,AuditSchemaVersion=1,ServerID=wbrbwm7qi1:5555,SessionID=c8231fb0c11311e1872d8aebd5d052bf,SessionState=2,UserID=Default,SessionName=172.18.186.11,Rpcs=0,Age=621422,$$$AUDITPROCESS={MemData:DefaultJDBCConfig_1=4},ERRORINFO=java.sql.SQLException: [sag-cjdbc42-0000][Oracle JDBC Driver][Oracle]ORA-01653: unable to extend table WMIS712.WMSESSION by 128 in tablespace WEBMDATA 2012-07-10 08:22:01 SAST [ISS.0095.0010E] AuditLogManager Runtime Exception: >>>BasicData:RootContextID=8faed230ca5711e1b0a6f6fdea974793,AuditTimestamp=1341901321940,ContextID=8faed230ca5711e1b0a6f6fdea974793,AuditSchemaName=wMSession,AuditSchemaVersion=1,ServerID=wbrbwm7qi1:5555,SessionID=8fac6130ca5711e1b0a3db011b193ad1,SessionState=2,UserID=Administrator,SessionName=system,Rpcs=0,Age=16<<< publishing log entry com.wm.app.audit.AuditException: [BAA.0002.0000] Wrapped Exception: com.wm.app.store.TSException: [BAT.0002.0000] Wrapped Exception: com.wm.txn.TransactionException: [BAC.0002.0000] Wrapped Exception: com.wm.txn.TransactionException: [BAF.0003.0072] BAF.0003.0072 .

Upvotes: 0

Views: 277

Answers (2)

If you just need to know whether your string exists or not, you could just use stringInstance.contains("our string").

However, a very simple regex should be .*YOURTEXTHERE.* -> .* denotes any character (0 or more) and followed by your string followed by any character (0 or more).

Nevertheless, this regex just gives you an indication whether the string exists or not. In fact, the contains(String) method may be a better choice.

Additionally, as @thatidiotguy already said, if you need to know where exactly this string occurs you could use indexOf or if you may want to find the same string more than once a Matcher with a compiled regex pattern.

Hope this helps! :-)

Upvotes: 0

thatidiotguy
thatidiotguy

Reputation: 8981

If you know the exact text why don't you just use String's indexOf?

Upvotes: 2

Related Questions