英文:
Regex for label=username and then isolate it
问题
这可能很简单,但我是一个初学者,找不到答案。
所以这是我的测试字符串,我需要将用户名转换为标签。
我认为使用下面的代码,我已经将用户名转换为标签。
{filename="/folder/folder/folder/folder/folder/folder/File.lgw"} |= ]:The referenced account is currently locked out and may not be logged on to.
| regexp "(?P
我在regex101上使用这个测试字符串,试图正确地隔离用户名。
[Listener 00_TEST_ACCOUNT_LOCK, address 00_TEST-ACCOUNT-LOCK_USER:username]:The referenced account is currently locked out and may not be logged on to.
我只需要保留代码的开头部分,即:
[Listener 00_TEST_ACCOUNT_LOCK, address 00_TEST-ACCOUNT-LOCK_USER:
我可以在用户名的开头和结尾添加任何内容以更好地识别它,稍后可以更改以匹配服务器示例:--username--
我已经尝试了一个非常简单的正则表达式:.*--
,但我卡在那里,不知道还能尝试什么或者这是否正确。
英文:
This may be so simple, but im a initiate and i don't find a answer to this.
So this is my test string, i need to convert the username to a label.
I think with this code below i already converted the username as a label.
{filename="/folder/folder/folder/folder/folder/folder/File.lgw"} |= `]:The referenced account is currently locked out and may not be logged on to.`| regexp "(?P<username>)"| line_format "{{.username}}"
I am using this Test string on regex101 trying to isolate the username correctly.
[Listener 00_TEST_ACCOUNT_LOCK, address 00_TEST-ACCOUNT-LOCK_USER:username]:The referenced account is currently locked out and may not be logged on to.
I only need keep the beggining part of the code that is:
[Listener 00_TEST_ACCOUNT_LOCK, address 00_TEST-ACCOUNT-LOCK_USER:
I can add anything to the start and end of the username to better identify it, it can be changed later on to match the server example: --username--
I already tried something so simple as a regular expression of: .*--
but im stuck there i i don't know what else i can try or if its even good
答案1
得分: 0
因为Oracle不支持look at heads,所以你无法使用regexp_substr
来实现你想要的功能。
然而,与其匹配你想要的内容,你可以匹配你不想要的内容,并用空白替换它,从而得到你想要的结果:
regexp_replace(my_column, ':username.*', ':')
英文:
Because Oracle does not support look at heads you can't do what you want using regexp_substr
.
However, rather than matching what you want, you can match what you * don't* want and replace it with blank, leaning you with what you want:
regexp_replace(my_column, ':username.*', ':')
专注分享java语言的经验与见解,让所有开发者获益!
评论