0

Very simple, but I cannot get it to work.

I want to find two words inside a continous string (or one whole word)

example

Find me the two words - "student" and "name" only in whole strings (unseparated with whitespace or other words/chars)

So find it in these...

"studentname"

"studentpreferredname"

"studentgivennames"

"student_name"

"student(^&(&(&(&&^&^&^&^&^%&^%name"

But not in these ...

"student name"

"student [multiple spaces] name"

"student is their name"

"the student's name is"

"A long time ago I wanted this student to have a similar name to"

The only thing I can get to sort of work is regex:

student.*name

But that brings in the cases above with all sorts of characters and words inbetween.

Thank you

UPDATE

See answer below.

This worked perfectly.

\bstudent\S*name\b

Fandango68
  • 4,461
  • 4
  • 39
  • 74

3 Answers3

0

If I understand your question correctly, you are trying to match with no space character between student and name.

If that is the case, try student[^ ]*name. [^ ] matches a character that is not a space.

Chuancong Gao
  • 654
  • 5
  • 7
  • No. Not just those with a space(s) in between. I want to find the words STUDENT and NAME inside a WHOLE word (string). Not those with words and spaces inbetween, if you know what I mean. – Fandango68 Mar 21 '16 at 04:30
0

A dot in regular expressions /./ is any character except a newline, that's why it doesn't work for you.

You probably need to use a non-whitespace character /\S/, which is a simpification of /[^ \t\r\n\f]/. Finally, your regex should look like this:

/student\S*name/

You can read more about regular expressions in Ruby in documentation.

Walerian Sobczak
  • 817
  • 2
  • 10
  • 23
  • Sorry I gave you kudos, but I've removed them. The above does not work. I am using grepWin and its Test regex feature. I've typed simple "studentname" and no match. I've tried "studentpreferredname" and again no match. – Fandango68 Mar 21 '16 at 05:33
  • Actually it did work. I just needed to replace the '/' with '\b' – Fandango68 Mar 21 '16 at 06:26
  • 1
    It's because I used `Ruby` syntax for Regex. I'm glad I could help. – Walerian Sobczak Mar 21 '16 at 06:28
0

This resolved it for me (from here).

\bstudent\S*name\b

Community
  • 1
  • 1
Fandango68
  • 4,461
  • 4
  • 39
  • 74