How find word before “,”?
up vote
1
down vote
favorite
So, my question:
I make this regex for find words, but i found problem on my regex.
Input: local lvlr,lvll = Audiosource:GetLevel()
@"(local.(?<vars>.*?)=)"
Output: lvlr,lvll
But I need them to be separated and were in the same group. It's possible ?
For example
Output: lvlr
Output: lvll
c# regex
add a comment |
up vote
1
down vote
favorite
So, my question:
I make this regex for find words, but i found problem on my regex.
Input: local lvlr,lvll = Audiosource:GetLevel()
@"(local.(?<vars>.*?)=)"
Output: lvlr,lvll
But I need them to be separated and were in the same group. It's possible ?
For example
Output: lvlr
Output: lvll
c# regex
Please, define what is a good definition for you for a word. If you have a regex to define what a word is for you, a good regex is(<your_regex_for_a_word>),
, and use$1
to get the word :).
– Luis Colorado
Nov 22 at 7:18
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
So, my question:
I make this regex for find words, but i found problem on my regex.
Input: local lvlr,lvll = Audiosource:GetLevel()
@"(local.(?<vars>.*?)=)"
Output: lvlr,lvll
But I need them to be separated and were in the same group. It's possible ?
For example
Output: lvlr
Output: lvll
c# regex
So, my question:
I make this regex for find words, but i found problem on my regex.
Input: local lvlr,lvll = Audiosource:GetLevel()
@"(local.(?<vars>.*?)=)"
Output: lvlr,lvll
But I need them to be separated and were in the same group. It's possible ?
For example
Output: lvlr
Output: lvll
c# regex
c# regex
asked Nov 19 at 11:19
Gigabait
234
234
Please, define what is a good definition for you for a word. If you have a regex to define what a word is for you, a good regex is(<your_regex_for_a_word>),
, and use$1
to get the word :).
– Luis Colorado
Nov 22 at 7:18
add a comment |
Please, define what is a good definition for you for a word. If you have a regex to define what a word is for you, a good regex is(<your_regex_for_a_word>),
, and use$1
to get the word :).
– Luis Colorado
Nov 22 at 7:18
Please, define what is a good definition for you for a word. If you have a regex to define what a word is for you, a good regex is
(<your_regex_for_a_word>),
, and use $1
to get the word :).– Luis Colorado
Nov 22 at 7:18
Please, define what is a good definition for you for a word. If you have a regex to define what a word is for you, a good regex is
(<your_regex_for_a_word>),
, and use $1
to get the word :).– Luis Colorado
Nov 22 at 7:18
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
It is possible to do with C# regex because each capturing group keeps track of each capture inside a group capture collection. However, your regex needs some adjustment for that feature to work.
It can look like
blocals+(?:(?<vars>w+),?s*)+=
See the regex demo. A more efficient version of the regex is
blocals+(?<vars>w+)(?:,s*(?<vars>w+))*s*=
Details
b
- a word boundary
local
- a substring
s+
- 1+ whitespaces
(?:(?<vars>w+),?s*)+
- 1 or more occurrences of
(?<vars>w+)
- Group "vars": 1 or more word chars
,?s*
- an optional,
followed with 0+ whitespaces
=
- a=
symbol.
See an example C# code:
var s = "local lvlr,lvll = Audiosource:GetLevel()";
var pattern = @"blocals+(?:(?<vars>w+),?s*)+=";
var result = Regex.Matches(s, pattern)
.Cast<Match>().Select(p => p.Groups["vars"].Captures)
.ToList();
foreach (var coll in result)
foreach (var v in coll)
Console.WriteLine(v);
Output:
lvlr
lvll
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
It is possible to do with C# regex because each capturing group keeps track of each capture inside a group capture collection. However, your regex needs some adjustment for that feature to work.
It can look like
blocals+(?:(?<vars>w+),?s*)+=
See the regex demo. A more efficient version of the regex is
blocals+(?<vars>w+)(?:,s*(?<vars>w+))*s*=
Details
b
- a word boundary
local
- a substring
s+
- 1+ whitespaces
(?:(?<vars>w+),?s*)+
- 1 or more occurrences of
(?<vars>w+)
- Group "vars": 1 or more word chars
,?s*
- an optional,
followed with 0+ whitespaces
=
- a=
symbol.
See an example C# code:
var s = "local lvlr,lvll = Audiosource:GetLevel()";
var pattern = @"blocals+(?:(?<vars>w+),?s*)+=";
var result = Regex.Matches(s, pattern)
.Cast<Match>().Select(p => p.Groups["vars"].Captures)
.ToList();
foreach (var coll in result)
foreach (var v in coll)
Console.WriteLine(v);
Output:
lvlr
lvll
add a comment |
up vote
3
down vote
accepted
It is possible to do with C# regex because each capturing group keeps track of each capture inside a group capture collection. However, your regex needs some adjustment for that feature to work.
It can look like
blocals+(?:(?<vars>w+),?s*)+=
See the regex demo. A more efficient version of the regex is
blocals+(?<vars>w+)(?:,s*(?<vars>w+))*s*=
Details
b
- a word boundary
local
- a substring
s+
- 1+ whitespaces
(?:(?<vars>w+),?s*)+
- 1 or more occurrences of
(?<vars>w+)
- Group "vars": 1 or more word chars
,?s*
- an optional,
followed with 0+ whitespaces
=
- a=
symbol.
See an example C# code:
var s = "local lvlr,lvll = Audiosource:GetLevel()";
var pattern = @"blocals+(?:(?<vars>w+),?s*)+=";
var result = Regex.Matches(s, pattern)
.Cast<Match>().Select(p => p.Groups["vars"].Captures)
.ToList();
foreach (var coll in result)
foreach (var v in coll)
Console.WriteLine(v);
Output:
lvlr
lvll
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
It is possible to do with C# regex because each capturing group keeps track of each capture inside a group capture collection. However, your regex needs some adjustment for that feature to work.
It can look like
blocals+(?:(?<vars>w+),?s*)+=
See the regex demo. A more efficient version of the regex is
blocals+(?<vars>w+)(?:,s*(?<vars>w+))*s*=
Details
b
- a word boundary
local
- a substring
s+
- 1+ whitespaces
(?:(?<vars>w+),?s*)+
- 1 or more occurrences of
(?<vars>w+)
- Group "vars": 1 or more word chars
,?s*
- an optional,
followed with 0+ whitespaces
=
- a=
symbol.
See an example C# code:
var s = "local lvlr,lvll = Audiosource:GetLevel()";
var pattern = @"blocals+(?:(?<vars>w+),?s*)+=";
var result = Regex.Matches(s, pattern)
.Cast<Match>().Select(p => p.Groups["vars"].Captures)
.ToList();
foreach (var coll in result)
foreach (var v in coll)
Console.WriteLine(v);
Output:
lvlr
lvll
It is possible to do with C# regex because each capturing group keeps track of each capture inside a group capture collection. However, your regex needs some adjustment for that feature to work.
It can look like
blocals+(?:(?<vars>w+),?s*)+=
See the regex demo. A more efficient version of the regex is
blocals+(?<vars>w+)(?:,s*(?<vars>w+))*s*=
Details
b
- a word boundary
local
- a substring
s+
- 1+ whitespaces
(?:(?<vars>w+),?s*)+
- 1 or more occurrences of
(?<vars>w+)
- Group "vars": 1 or more word chars
,?s*
- an optional,
followed with 0+ whitespaces
=
- a=
symbol.
See an example C# code:
var s = "local lvlr,lvll = Audiosource:GetLevel()";
var pattern = @"blocals+(?:(?<vars>w+),?s*)+=";
var result = Regex.Matches(s, pattern)
.Cast<Match>().Select(p => p.Groups["vars"].Captures)
.ToList();
foreach (var coll in result)
foreach (var v in coll)
Console.WriteLine(v);
Output:
lvlr
lvll
answered Nov 19 at 11:26
Wiktor Stribiżew
303k16123199
303k16123199
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373520%2fhow-find-word-before%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please, define what is a good definition for you for a word. If you have a regex to define what a word is for you, a good regex is
(<your_regex_for_a_word>),
, and use$1
to get the word :).– Luis Colorado
Nov 22 at 7:18