Question: Starting with this `L Hernandez`

From a vector containing the following: 

```
[1] "HernandezOlaf "    "HernandezLuciano " "HernandezAdrian "

```

I tried this:

```
'subset(ABC, str_detect(ABC, "L Hernandez") == TRUE)'

```

The name Hernandez which includes the capital L anyplace is the desired output. 

The desired output is `HernandezLuciano`

Answer: 
May be this helps:

```
vec1 <- c("L Hernandez", "HernandezOlaf ","HernandezLuciano ", "HernandezAdrian ")
grep("L ?Hernandez|Hernandez ?L",vec1,value=T)
#[1] "L Hernandez" "HernandezLuciano "

```

### Update

```
variable <- "L Hernandez"

v1 <- gsub(" ", " ?", variable) #replace space with a space and question mark 
v2 <- gsub("([[:alpha:]]+) ([[:alpha:]]+)", "\\2 ?\\1", variable) #reverse the order of words in the string and add question mark

```

You can also use `strsplit` to split `variable` as @rawr commented

```
grep(paste(v1,v2, sep="|"), vec1,value=T)
#[1] "L Hernandez"       "HernandezLuciano "

```
You could use `agrep` function for approximate string matching.
If you simply run this function it matches every string...

```
agrep("L Hernandez", c("HernandezOlaf ",    "HernandezLuciano ", "HernandezAdrian "))
[1] 1 2 3

```

but if you modify this a little "L Hernandez" -> "Hernandez L"

```
agrep("Hernandez L", c("HernandezOlaf ",    "HernandezLuciano ", "HernandezAdrian "))
[1] 1 2 3

```

and change the max distance

```
agrep("Hernandez L", c("HernandezOlaf ",    "HernandezLuciano ", "HernandezAdrian "),0.01)
[1] 2

```

you get the right answer. This is only an idea, it **might** work for you :)