Regular Expression : Match till the ( character or the end of the buffer) but not the character

StackOverflow https://stackoverflow.com/questions/22804767

  •  26-06-2023
  •  | 
  •  

문제

Given the following contents in the smb.conf file. How to remove the [share_11999] section using boost(perl version) regex. The problem is the section [share_11999] can be at the end of the file.

The following regex almost works except that it removes the "[" of the next section.

"[[a-zA-Z0-9_-]+?][^\[]+?path = /store/11999.*?(\'|\[)"

[share_11920]
path = /store/11920
writeable = yes
create mask = 0755

[share_11999]
path = /store/11999
writeable = yes
create mask = 0755

[share_12435]
path = /store/12435
writeable = yes
create mask = 0755

Basically the problem is to match anything until a character except the character or the end of the buffer.

도움이 되었습니까?

해결책

To answer your general question: "How to match anything until a character except the character?"
You can use the following regex:

"(.*)(?=word)"

This uses the "look ahead / look behind" construct (?=something) to match everything until the certain word and excluding that word.

Example

Test string ==> 'I don't understand the meaning of this word or anything else'
"(.*)(?=word)" applied
'I don't understand the meaning of this'

Demo

http://regex101.com/r/nE4dS6

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top