How to search for a word in a sentence using Regex

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By aagoldberg

I’m using regex to search for a word that the user inputs in LineEdit, and print true if the word is found. Yet instead of printing true if the complete word (“message” in this case) is found, regex will print true if any letter of the word is found. Any suggestions?
Here is my code:

		var regex = RegEx.new()
		regex.compile(new_text)
		var result = regex.search("message")
		if result:
			print("true")```
:bust_in_silhouette: Reply From: duke_meister

You need to call compile() on the regex pattern, in your case “message”, and call search() on the text to search, in your case new_text. You have them backwards. That’s after a quick read of the docs, I haven’t used it in Godot before.

Why aren’t you just using the string functions, like find()?
docs