Victor M. Pereira wrote:I'm not sure if I fully understand what you want, but it seems that your regex is missing a couple of things.
First, the regex you wrote is telling me that the String must begin with "SchemaValidationException" or it must not have Caused By ...
I believe that you are seeking something like: ([a-Z]|[0-9])*(SchemaValidationException|!(Caused by: org.xml.sax.SAXParseException: cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type 'NonEmptyString'.))+([a-Z]|[0-9])*
I recommend trimming the String since spaces complicate the regex and one missing space might ruined your method.
That would be with regex however from your test case seems that indexOf would be easier to apply.
Winston Gutkowski wrote:
pkinuk Buler wrote:Can anyone help me to write the regex?
Regexes were designed for (originally) string patterns contained in a single line and, although they've been expanded to include multi-line matches, I'd suggest that whatever regex you come up with is likely to be unwieldly.
Seems to me that you are searching for two patterns in a multi-line block, so my pseudo-code would look something like:but I'm quite sure there are other solutions.
[Edit] @pkinuk: Above is not quite right. You shouldn't read a new line in the outer loop if a match on the 1st string was already found; I leave it to you to correct.
Henry Wong wrote:
pkinuk Buler wrote:Hi all,
I've gone through a lots of examples in JavaRanch/Other websites, but I still can't write a regex to finish : include a text but exclude another text in the one regex
I have an example: [tt]haha.hello.common.exceptions.SchemaValidationException: Validated XML message - message invalid. [Error Code cegst01_350]\r\n\n\tat haha.hello.common.util.XMLUtility.validateMessage(XMLUtility.java:257)\n\tat haha.hello.mama.papa.release2.socketxml.readers.InputReaderBaseImpl.a(InputReaderBaseImpl.java:7)\n\tat haha.hello.mama.papa.release2.socketxml.readers.InputReaderBaseImpl.<init>(InputReaderBaseImpl.java:1)\n\tat the String is a little bit too long, but it was an log message. What I planned to do in one regex is:
1. Check if the text contains
2. Make sure the text doesn't contain
The Matcher.find() will return true only if the text fulfill above conditions.
Can anyone help me to write the regex?
Thank you in advance
The easiest way to do this is to have a negative look-ahead (generally from the beginning of the regex) attached to the regex search for the item that you want. With the negative look-ahead, the regex will always fail, if it finds the component that it doesn't want.
Using look aheads is pretty advanced, so I suggest that you start there, but don't be surprised if you run into trouble and have to backtrack to learn other parts of regex first.
SchemaValidationException(?(?!\QCaused by: org.xml.sax.SAXParseException: cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type 'NonEmptyString'.\E).)*(?:\s)*)*
SchemaValidationException: Validated XML message - message invalid. [Error Code cegst01_350]\r\n\n\tat com.qxlva.common.util.XMLUtility.validateMessage(XMLUtility.java:257)\n\tat com.qxlva.nhs.api.release2.socketxml.readers.InputReaderBaseImpl.a(InputReaderBaseImpl.java:7)\n\tat com.qxlva.nhs.api.release2.socketxml.readers.InputReaderBaseImpl.<init>(InputReaderBaseImpl.java:1)\n\tat com.qxlva.nhs.api.release2.socketxml.readers.InputReaderWithSSODataImpl.<init>(InputReaderWithSSODataImpl.java:11)\n\tat com.qxlva.nhs.api.release2.socketxml.readers.GetRolesReaderImpl.<init>(GetRolesReaderImpl.java:4)\n\tat com.qxlva.nhs.api.release2.socketxml.CoreInputReaderFactoryImpl.newInputReader(CoreInputReaderFactoryImpl.java:85)\n\tat com.qxlva.nhs.api.release2.socketxml.CoreInputReaderFactoryImpl.newInputReader(CoreInputReaderFactoryImpl.java:14)\n\tat com.qxlva.nhs.api.release2.socketxml.CoreInputReaderFactoryImpl.newInputReader(CoreInputReaderFactoryImpl.java:52)\n\tat com.qxlva.nhs.api.socket.protocols.NewlineDelimitedAPIBridge.process(NewlineDelimitedAPIBridge.java:108)\n\tat com.qxlva.nhs.api.socket.protocols.NewlineDelimitedAPIBridge.process(NewlineDelimitedAPIBridge.java:20)\n\tat com.qxlva.nhs.api.socket.SocketConnection.d(SocketConnection.java:29)\n\tat com.qxlva.nhs.api.socket.SocketConnection.run(SocketConnection.java:172)\n\tat com.qxlva.nhs.api.socket.SocketThreadManager$SocketThread.run(SocketThreadManager.java:7)\n
Paul Clapham wrote:
pkinuk Buler wrote:Hi all,
Here is my scenario:
1. I set my application using the BASIC auth-method in the web.xml file...
... What I expected is to show the BASIC login box to user and ask them to perform the authentication when a session is created. (Logout user and ask them re-login when the session is timed out)
However, what i found was different what i expected, every time i start a Tomcat server, it allowed me to set the user name and password once. Even thought a new session is created after the current session expired, i still couldn't see the login in box to pop up again unless i closed the browser.
Could anyone give me some advices to help me solve this problem?
Then your expectation was wrong. What you describe is exactly how browsers implement the basic authentication method. They ask the user for the credentials once per browsing session and cache the credentials.
So if you want something different -- and you do -- then you can't use basic authentication.