[string] Lua String replace

How would i do this?

I got this:

name = "^aH^ai"
string.gsub(name, "^a", "")

which should return "Hi", but it grabs the caret character as a pattern character

What would be a work around for this? (must be done in gsub)

This question is related to string replace lua gsub lua-patterns

The answer is


Try:

name = "^aH^ai"
name = name:gsub("%^a", "")

See also: http://lua-users.org/wiki/StringLibraryTutorial


Examples related to string

How to split a string in two and store it in a field String method cannot be found in a main class method Kotlin - How to correctly concatenate a String Replacing a character from a certain index Remove quotes from String in Python Detect whether a Python string is a number or a letter How does String substring work in Swift How does String.Index work in Swift swift 3.0 Data to String? How to parse JSON string in Typescript

Examples related to replace

How do I find and replace all occurrences (in all files) in Visual Studio Code? How to find and replace with regex in excel How to replace text in a column of a Pandas dataframe? How to replace negative numbers in Pandas Data Frame by zero Replacing few values in a pandas dataframe column with another value How to replace multiple patterns at once with sed? Using tr to replace newline with space replace special characters in a string python Replace None with NaN in pandas dataframe Batch script to find and replace a string in text file within a minute for files up to 12 MB

Examples related to lua

How do I append to a table in Lua List file using ls command in Linux with full path Check if a string isn't nil or empty in Lua Roblox Admin Command Script How to add a "sleep" or "wait" to my Lua Script? How to iterate through table in Lua? Not Equal to This OR That in Lua How to read data from a file in Lua Lua string to int How to check if matching text is found in a string in Lua?

Examples related to gsub

Replace specific characters within strings Remove pattern from string with gsub Lua String replace

Examples related to lua-patterns

Lua String replace