Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Cómo agregar hashtag y mención en textInput react-native

Me enfrento a este desafío cuando el cliente quiere que agregue una mención y un hashtag a la entrada de texto, se verá así

ingrese la descripción de la imagen aquí

Probé algunas lib, pero no me dan un resultado como este, así que traté de hacer una personalizada, pero me pregunto cómo podemos detectar cuando escribimos "@" o "#", luché durante días debido a esto, por favor ayuda

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Regex es perfecto para esto:

 inputStr.replace(/(?<=#).*?(?=( |$))/g, hashtag => { // do something with hashtag, eg "fenty" return hashtag; });

Desglosando la expresión regular:

 (?<=#) # match anything preceded by "#" .*? # match everything without greedy matching ( ?= # match anything with the following after it: ( |$) # space or end of text )

g (global) significa hacer coincidir todas las ocurrencias.

Se puede hacer lo mismo para @ :

 inputStr.replace(/(?<=@).*?(?=( |$))/g, mention => { // mention == "fenty" return mention; });

También puede realizar manipulaciones en, digamos, los hashtags para convertirlos en enlaces o lo que sea:

 const newString = inputStr.replace(/(?<=#).*?(?= )/g, hashtag => { // do something with hashtag, eg "fenty" return `<a href="/hashtags/${hashtag}">${hashtag}</a>`; // "stunna new year highlighter <a href="/hashtags/fenty">fenty</a> @fenty" });

Manifestación:

 "hello #yes no #maybe so #ionter6 #000".replace(/(?<=#).*?(?=( |$))/g, hashtag => { console.log("Hashtag from post:", hashtag); return hashtag; });

about 4 years ago · Juan Pablo Isaza Report

0

Creo que deberías probar esta biblioteca, hice lo mismo usando las menciones controladas de forma nativa.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!