score:0
Accepted answer
if the 2 words only use the alphabets without any special characters.
you can use the simplest one. /^([a-z]+)\s+([a-z]+)(\s*)$/gi
[a-z]+ tells any character in the alphabet with quantifier of one or more
\s* -> is a space with a quantifier of zero or more
i -> on the last part tells case-insensitive matching
let a = 'my word';
let b = 'oneword';
let c = 'using three words';
let d = 'onewordwithspace ';
let e = 'my wordwithspace ';
let regex = /^([a-z]+)\s+([a-z]+)(\s*)$/gi;
console.log((regex.test(a))); // true
console.log((regex.test(b))); // false
console.log((regex.test(c))); // false
console.log((regex.test(d))); // false
console.log((regex.test(e))); // true
score:1
you can try this :
([a-za-z]+)\s([a-za-z]+)$
Source: stackoverflow.com
Related Query
- Regex for 2 words, non-numeric, and one space
- Best practices for React, Redux and Websocket (Keeping one class to handle requests)
- How to make an electron react app, which has 2 windows - a general one and one for the Tray
- Why create both index.js and Component.js for one component in React?
- Non breaking space for React?
- Regex for checking if a string should not contain certain words but those words are ok if they have a 'to' or 'for' preceeding the words
- JS Regex for first letters only, but if the word it only two letters keep both AND numbers as is
- react one defintion route path for edit and add form
- start and end date should be different for one year
- JavaScript Regex for first character alphabet only, second and onwards can be alphanumeric or special characters (hyphen, comma and whitespace)
- When you want to change User's data, should you delete the jwt and create a new one for the session?
- Regex for input with numbers and commas
- React js regex find all words beginning and ending with __
- useReducer() is returning data for one component and for other component it is returning the initialState
- How can i avoid adding duplicates into array and only have one value at time for specific attribute?
- React SSR(Server Side Rendering) for SEO before login and after login Create React App (CRA). How to do this in one project folder?
- Hello everyone! I cannot combine two states in one state . I have created one state for input values and one state for image uploader
- How to mock multiple promise .then in react hooks and check for state set in one .then
- How can you make a conditional external script reference in the public html file in reactjs. i.e. one for production and one for staging
- I have 2 components and I want a 3rd component to show animation while waiting for the 2nd one to load images
- Regex for 8 digits non repeating numbers
- Using regex with Yup to validate full name with extended latin alphabet only and a minimum of 2 words
- Regex expression for start and end with characters in between numbers
- How to add the option to allow only one space in a regex
- HighCharts Line Chart draw y axis line for entire line points and only one line
- Manipulate JSON key values with one header row array and rest header values array for table
- For a component in React with Reux, how to not fire mouse event in one case and how to fire mouse event in another case
- How to do an "ellipsis" like effect for non string elements and restrict rows up to 2?
- Variable assignment from JSON not setting all the values at the same time (React) and returning undefined for one variable
- Redux form, clear and rest for one specific field, react JS
More Query from same tag
- React router on electron can't change history
- Background image added for div tag is not working... What are the possible approaches?
- How to capture paste event anywhere on page in React?
- If condition in hover status in styled-component always takes the "else" value
- How to block double sending when onclick button?
- Unable to update the state value in React Js forms
- .filter function "is not a function" error
- Recoil: parent state does not update when atomFamily is set
- TimeoutException: Asp.net Core 2.2 with react , requests timeout period of 50 seconds
- Two drag and drop libraries having conflict
- How to return falsy from a React component?
- useState with value that may be null
- Prefixing imported CSS file
- How to change a copy of a component's state without changing the component's state?
- facing quite strange issue in popup closing in react. method is getting called but popup is not closing
- How can I add a click event on an individual Element in a mapped array in react
- Deeply updating React state (array) without Immutable, any disadvantages?
- How can I test chained React hooks in Jest?
- Does useMemo hooks in React.js also memoizes object reference as well?
- onClick is not firing the function correctly in React
- ReactJs: return only unique values from an array
- How to fix get request and response with whole html
- How to invoke hooks in different components based on RESTful fetch call?
- Using React context to maintain user state
- How to pipe a pdf download response from an api (node/express) to a client (react)?
- Custom React Hook on Ctrl+S keydown
- Using Map To Create Components - but functions are tied to each other
- Testing results for async calls made in useEffect hook
- How to style function-plot.js
- how to use proxy in react build?