How can I convert this code to return matches in array by substring?

Fane

I have the following array:

arr = ["lol","test"]

and a code:

matches = content.downcase.split & arr

where content is a string. This code returns ["lol"] when content = "Something lol", but fails to return anything when content = "Something #lol." with a comma or hashtag etc. It always fails when there is no exact match.

I'd like to match with the strings in the array as substring. How can this be done by adapting the above code?

Wand Maker

Try splitting on non-word boundary as shown below

arr = ["lol","test"]

content = "Something #lol."
p matches = content.downcase.split(/\W/) & arr

Outputs

["lol"]

Sample runs from Try ruby is shown below

enter image description here

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How can I return true only if one of a set of strings matches?

分類Dev

How can I iterate over array and get the count of matches?

分類Dev

How can I push regex matches to array in java?

分類Dev

How can I convert an async iterator to an array?

分類Dev

How can I convert a cell array into a numeric array in MATLAB?

分類Dev

How can I convert an array name to an array pointer in C?

分類Dev

How can I get the index of an object in an array with a property value that matches a specific criteria?

分類Dev

How can I convert a comma-separated string to an array?

分類Dev

How can I convert a numpy array to a matrix with counts of occurences?

分類Dev

How can I convert a two column array to a matrix with counts of occurences?

分類Dev

How can i convert a text into an array of useful data?

分類Dev

How can I convert this object to an array and access values by key in React?

分類Dev

How can I convert spectrogram data to a tensor (or multidimensional numpy array)?

分類Dev

How can I convert a array.map().toList to a generic type?

分類Dev

How can I get textbox value into array and convert into integer in java

分類Dev

How can I order by a substring of the cell value?

分類Dev

How can I convert an array of arrays to an array of objects, selecting the key from other array?

分類Dev

How can I use Python to convert RGB565 byte array to RGB888 byte array?

分類Dev

Can I convert array of models into collection of models?

分類Dev

How can I return compact head() and tail() results from the same code line with Rmarkdown/Knitr?

分類Dev

How can I programmatically tell if a filename matches a shell glob pattern?

分類Dev

How can I exclude newlines in Scala RegexParsers matches?

分類Dev

How can I tell if my vector matches the variable values in r?

分類Dev

How can I write a flex pattern that matches the null language?

分類Dev

How can I find the nth substring in between two substrings in C?

分類Dev

how can i call return array from Swift class to swiftui view file

分類Dev

How can I initialize an array of its length equal to the return of a const int method?

分類Dev

How can I use Array.filter() to return items in blocks of 2?

分類Dev

How can I convert an ArrayList of floats to a primitive float array using java 8 streams?

Related 関連記事

  1. 1

    How can I return true only if one of a set of strings matches?

  2. 2

    How can I iterate over array and get the count of matches?

  3. 3

    How can I push regex matches to array in java?

  4. 4

    How can I convert an async iterator to an array?

  5. 5

    How can I convert a cell array into a numeric array in MATLAB?

  6. 6

    How can I convert an array name to an array pointer in C?

  7. 7

    How can I get the index of an object in an array with a property value that matches a specific criteria?

  8. 8

    How can I convert a comma-separated string to an array?

  9. 9

    How can I convert a numpy array to a matrix with counts of occurences?

  10. 10

    How can I convert a two column array to a matrix with counts of occurences?

  11. 11

    How can i convert a text into an array of useful data?

  12. 12

    How can I convert this object to an array and access values by key in React?

  13. 13

    How can I convert spectrogram data to a tensor (or multidimensional numpy array)?

  14. 14

    How can I convert a array.map().toList to a generic type?

  15. 15

    How can I get textbox value into array and convert into integer in java

  16. 16

    How can I order by a substring of the cell value?

  17. 17

    How can I convert an array of arrays to an array of objects, selecting the key from other array?

  18. 18

    How can I use Python to convert RGB565 byte array to RGB888 byte array?

  19. 19

    Can I convert array of models into collection of models?

  20. 20

    How can I return compact head() and tail() results from the same code line with Rmarkdown/Knitr?

  21. 21

    How can I programmatically tell if a filename matches a shell glob pattern?

  22. 22

    How can I exclude newlines in Scala RegexParsers matches?

  23. 23

    How can I tell if my vector matches the variable values in r?

  24. 24

    How can I write a flex pattern that matches the null language?

  25. 25

    How can I find the nth substring in between two substrings in C?

  26. 26

    how can i call return array from Swift class to swiftui view file

  27. 27

    How can I initialize an array of its length equal to the return of a const int method?

  28. 28

    How can I use Array.filter() to return items in blocks of 2?

  29. 29

    How can I convert an ArrayList of floats to a primitive float array using java 8 streams?

ホットタグ

アーカイブ